先来看一下效果:
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="js/jquery-1.12.2.min.js"></script>
<script>
$(function(){
$("#btn1").click(function(){
$(":checkbox").prop("checked",true);
})
$("#btn2").click(function(){
$(" :checkbox").prop("checked",false);
})
})
</script>
</head>
<body>
<input type="button" value="全选" id="btn1">
<input type="button" value="全不选" id="btn2">
<input type="checkbox">吃饭
<input type="checkbox">吃饭
<input type="checkbox">吃饭
<input type="checkbox">吃饭
<input type="checkbox">吃饭
<input type="checkbox">吃饭
</body>
</html>
总结:
prop()方法->全部进行操作。