zoukankan      html  css  js  c++  java
  • jQuery,遍历表格每个单元格数据。

                                    <table class="table table-hover table-bordered">
    		                                            <thead>
    		                                                <tr>
    		                                                    <th ><input name="selectAll" type="checkbox" class="J_selectAll"></th>
    		                                                    <th>药名</th>
    		                                                    <th>剂量</th>
    		                                                    <th>次数/日</th>
    		                                                </tr>
    		                                            </thead>
    		                                            <tbody class="J_tbody">
    		                                            	<tr data-id = "1">
    		                                            		<td>
    		                                            			<input class="J_subCheck"  type="checkbox" name="subCheck" >
    		                                            		</td>
    		                                            		<td>1号药</td>
    		                                            		<td>1片</td>
    		                                            		<td>1</td>
    		                                            	</tr>
    		                                            	<tr data-id = "2">
    		                                            		<td>
    		                                            			<input class="J_subCheck"  type="checkbox" name="subCheck" >
    		                                            		</td>
    		                                            		<td>2号药</td>
    		                                            		<td>2片</td>
    		                                            		<td>2</td>
    		                                            	</tr>
    		                                            	<tr data-id = "3">
    		                                            		<td>
    		                                            			<input class="J_subCheck"  type="checkbox" name="subCheck" >
    		                                            		</td>
    		                                            		<td>1号药</td>
    		                                            		<td>3片</td>
    		                                            		<td>3</td>
    		                                            	</tr>
    		                                            	<tr data-id = "4">
    		                                            		<td>
    		                                            			<input class="J_subCheck"  type="checkbox" name="subCheck" >
    		                                            		</td>
    		                                            		<td>4号药</td>
    		                                            		<td>4片</td>
    		                                            		<td>4</td>
    		                                            	</tr>
    		                                            </tbody>
    		                                        </table>
    

      

    药名剂量次数/日
    1号药 1片 1
    2号药 2片 2
    1号药 3片 3
    4号药 4片 4
    var tr = $('.J_tbody').children('tr'), 
                list =[],
                id, medicinal, dosage, unit, times;
    
            tr.each(function(){ 
                var tdArr = $(this).children(),
                    id = $(this).attr('data-id'),
                    medicinal = tdArr.eq(1).text(),
                    dosage = tdArr.eq(2).text(),
                    times = tdArr.eq(3).text(),
                    trList = {};  //trList对象一定要声明在each()函数里,否者压入栈中的数据将会是最后一条数据乘以4。
                jQuery.extend(trList, {
                    id: id, 
                    medicinal: medicinal, 
                    dosage: dosage, 
                    times: times
                });
                list.push(trList);
            });
    
  • 相关阅读:
    linux最简单项目部署
    sql索引
    /etc/profile和~/.bash_profile区别
    Linux下查找软件的目录位置
    为什么要使用消息队列?
    idea中常用的快捷键
    PAT 甲级 1023 Have Fun with Numbers (20分)
    PAT《算法笔记》
    Text 2
    Text-1
  • 原文地址:https://www.cnblogs.com/yud123/p/7250633.html
Copyright © 2011-2022 走看看