一行代码搞定checkbox全选和全不选

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="check">
<input type="checkbox" onclick="checkAll(this)">全选<br><br>
<input type="checkbox">1<br>
<input type="checkbox">2<br>
<input type="checkbox">3<br>
<input type="checkbox">4<br>
<input type="checkbox">5<br>
<input type="checkbox">6<br>
<input type="checkbox">7<br>
<input type="checkbox">8<br>
<input type="checkbox">9<br>
</div>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
function checkAll(obj) {
$("#check input[type='checkbox']").prop('checked', $(obj).prop('checked'));
}
</script>
</html>

posted @ 2018-07-27 17:30  Ares0023  阅读(234)  评论(0)    收藏  举报