站长资源网络编程
jquery一键控制checkbox全选、反选或全不选
简介jquery attr()方法获取标签的 checked 会有问题,所以用了 prop() 方法。Hml的checkbox没有加name,只用了 div 嵌套。如有更好的方法,望指点!!//全选$('#allChecked').change(function()else{ // 如果有选中个数,-> 反选
$('#box').children(':checkbox').each(function(){
$(this).prop('checked',$(this).is(':checked')"htmlcode">
<div align="center">
<div id="box">
<input type="checkbox" value="1">西瓜
<input type="checkbox" value="2">芒果
<input type="checkbox" value="3">橙
<input type="checkbox" value="4">山竹
<input type="checkbox" value="5">草莓
<input type="checkbox" value="6">火龙果
</div>
<br>
<input type="checkbox" id="allChecked">全选
<input type="checkbox" id="invertChecked">反选
<input type="checkbox" id="orChecked">全选/反选/全不选
</div>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。