首先介绍的是checkbox状态判断:
$(this).is(":checked")
如果选中则返回true,未被选中则返回false。
然后给大家介绍全选效果实现(全不选只要将checked值改为false就可以了):
$("input[name='chooseactivity']").each(function(){
$(this).get(0).checked=true;
});
js控制复选框选中不选中状态,建议使用上面原生写法,因为用网上所说的jq方法可能会出现不生效的结果,jq方法:
$("input[type='checkbox']").attr("checked");
以上方法不建议使用。
完整的全选全不选代码如下:
$(document).on("click","input[name='chooseall']",function(){
if($(this).is(":checked")){
$("input[name='chooseactivity']").each(function(){
$(this).get(0).checked=true;
});
}else{
$("input[name='chooseactivity']").each(function(){
$(this).get(0).checked=false;
});
}
});