jquery遍历table

关于Jquery;相信你们已经很熟悉了,我最近的项目运用到关于Jquery的遍历事件;权当总结下: ui

遍历Table this

<table  id="thistab"> spa

<tr>
<td class="t_l_bg">3</td>
<td><span class="t_trash"></span></td>
<td>
<input type="text" class="ui_input" /> 事件

</td>
<td>
<input type="text" class="ui_input" /></td>
<td>
<input type="text" class="ui_input sumnum" /></td>
<td>
<input type="text" class="ui_input chagePrice" /></td>
<td>
<input type="text" class="ui_input chageAmount" /></td>
<td>
<input type="text" class="ui_input" /></td>
<td>
<input type="text" class="ui_input" /></td>
</tr> input

<tr>
<td class="t_l_bg">3</td>
<td><span class="t_trash"></span></td>
<td>
<input type="text" class="ui_input" /> io

</td>
<td>
<input type="text" class="ui_input" /></td>
<td>
<input type="text" class="ui_input sumnum" /></td>
<td>
<input type="text" class="ui_input chagePrice" /></td>
<td>
<input type="text" class="ui_input chageAmount" /></td>
<td>
<input type="text" class="ui_input" /></td>
<td>
<input type="text" class="ui_input" /></td>
</tr> table

</table> function

 

关于上面的table;我简单创建的 class

  $("#thistab tr").each(function () {}); select

这个事件是遍历表thistab中全部的tr

 

 

var leg = $("#thistab tr").length - 1
$("#thistab tr:gt(0):lt(" + leg + ")").each(function () {
temp = $(this).children("td").eq(6).children("input").val();
if (temp.length > 0) {
sumPrice += Number(temp);
}
});

代码 $("#thistab tr").length是获取table的行数

gt(0)表明是大于第一行,从第二行起

lt(10)表明小于;

只有遍历到了行以后,才能去遍历行下面的TD;或者td下的input;

$(this).children("td").eq(6).children("input").val(); 这段代码边上,当前行下第七列中的input的value值;

 

遍历checkbox

$('input[type="checkbox"][name="chk_list"]:checked').each(function () {
alert($(this).val());
});

全选/全不选

 $('input[name="chk_list"]').attr("checked", this.checked);

 

遍历select

$('select[name="selectlist"] option:selected').each(function () { alert($(this).val()+"-"+$(this).text()) });

相关文章
相关标签/搜索