首页 > Web开发 > 详细

利用jQuery实现全选、全不选、反选(checkBox)

时间:2018-02-06 21:27:40      阅读:236      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="jquery-1.8.3.js"></script>
</head>
<body>
<input type="checkBox" class="all">全选/全不选
<br>
<input type="checkBox" class="un">反选
<hr>
<div id="main">
<input type="checkBox">篮球
<br>
<input type="checkBox">羽毛球
<br>
<input type="checkBox">乒乓球
<br>
<input type="checkBox">足球
<br>
<input type="checkBox">橄榄球
<br>
<input type="checkBox">棒球
</div>
</body>
<script type="text/javascript">
// 全选和全不选举
$(‘.all‘).click(function(){
$(‘#main input‘).attr(‘checked‘,this.checked);
});
// 反选
$(‘.un‘).click(function(){
$(‘#main input‘).each(function(){
this.checked=!this.checked; // 进行反选
});

});
</script>
</html>

利用jQuery实现全选、全不选、反选(checkBox)

原文:http://blog.51cto.com/11871779/2069578

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