Jq遍历全选全不选反选

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

//全选 全不选

$('#checkAll').click(function () {

//判断是否被选中

var bischecked = $('#checkAll').is(':checked');

var fruit = $('input[name="check"]');

bischecked ? fruit.attr('checked', true) : fruit.attr('checked', false);

});

//反选 遍历checkbox 如果当前为选中 就设置为 不选中 反之相同

$("#tabVouchList tr").each(function () {

if ($("td:eq(0) input[name='check']", $(this)).is(':checked')) {

$(this).attr('checked', false);

} else {

$(this).attr('checked', true);

}

});

HTML table<table id="tabVouchList">

<tr>

<th>

<input type="checkbox" name="checkAll" />

</th>

<th>

行号

</th>

<th>

名称

</th>

</tr>

<tr>

<td>

<input type="checkbox" name="check" />

</td>

<td>

行号

</td>

<td>

名称

</td>

</tr>

</table>

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航