使用jQuery实现复选框的全选、反选和不选
通过给按钮绑定点击事件来控制
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="../js/jquery-1.11.3.js"></script>
</head>
<body>
<form id="list" action="">
<input type="checkbox" class="checkbox">
<input type="checkbox" class="checkbox">
<input type="checkbox" class="checkbox">
<input type="checkbox" class="checkbox">
<input type="checkbox" class="checkbox"><br>
<input id="all" type="checkbox">全选
<button id="aga" type="button">反选</button>
<button id="not_all" type="button">不选</button>
</form>
<script>
$(function (){
$('#list>#all').click(function (){
$('#list>.checkbox').prop('checked',$(this).prop('checked'));
})
$('#list>#aga').click(function (){
$('#list>.checkbox').prop('checked',function (i,e){
return !e;
})
})
$("#list>#not_all").click(function (){
$('#list>.checkbox').prop('checked',false);
})
})
</script>
</body>
</html>