首页 > 其他 > 详细

checkbox实现全选全不选

时间:2016-09-30 11:43:03      阅读:140      评论:0      收藏:0      [点我收藏+]
1.jQuery实现checkbox全选全不选

<!DOCTYPE html>
<head runat="server">
<title>jQuery实现CheckBox全选、全不选</title>
<meta charset="utf-8">
<script src="jquery-3.1.1.min.js"></script> 
<script type="text/javascript">
$(function() {
$("#checkAll").click(function() {
$(input[name="subBox"]).attr("checked",this.checked); 
});
var $subBox = $("input[name=‘subBox‘]");
$subBox.click(function(){
$("#checkAll").attr("checked",$subBox.length == $("input[name=‘subBox‘]:checked").length ? true : false);
});
});
</script>

</head>
<body>
<div>
<input id="checkAll" type="checkbox" />全选
<input name="subBox" type="checkbox" />项1
<input name="subBox" type="checkbox" />项2
<input name="subBox" type="checkbox" />项3
<input name="subBox" type="checkbox" />项4
</div>
</body>
</html>

 

checkbox实现全选全不选

原文:http://www.cnblogs.com/Gabriel-Wei/p/5923001.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!