全选/全不选
$(function() {//全选和全不选
$("#all").on("click",function() {//当我们点击按钮时
if (this.checked==true) {//如果复选框是选中的
$("input[name='id']").attr("checked","checked");//我们就让name=’id’的也选中
}else {//如果复选框不是选中的
$("input[name='id']").attr("checked",false);//我们就让name=”id”的也不选中
}
});
<form action="" method="post">
<input type="checkbox" id="all" />全选/全不选
</form>
这里是图片解释:
反选
<form action="" method="post">
<input type="checkbox" id="fan"/>反选
</form>
<script>
$("#fan").on("click",function(){ //反选
$("input[name='id']").each(function(){
$(this).attr("checked", !$(this).attr("checked"));
});
});
</script>
这里是图片解释: