<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="http://lib.sinaapp.com/js/jquery/2.0/jquery.min.js"></script>
</head>
<body>
<div>
<input type="checkbox" class="all-box" />全选
</div>
<div>
<input type="checkbox" class="chd-box"/>手机
</div>
<div>
<input type="checkbox" class="chd-box" />电脑
</div>
<div>
<input type="checkbox" class="chd-box" />平板
</div>
<div>
<input type="checkbox" class="chd-box" />内存卡
</div>
<div>
<input type="checkbox" class="chd-box" />影碟机
</div>
<script>
$(".all-box").change(e=>$(".chd-box").prop('checked',e.target.checked));
$(".chd-box").change(function () {
var all = $(".chd-box").length;
var sel = $(".chd-box:checked").length;
$(".all-box").prop('checked',all==sel);
})
</script>
</body>
</html>
jquery全选和反选
最新推荐文章于 2024-01-23 19:19:19 发布