首页 > Web开发 > 详细

使用jQuery实现全选、全不选、 反选(button)

时间:2018-02-06 17:59:29      阅读:232      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="jquery-1.8.3.js"></script>
</head>
<body>
<button>全选</button>
<button>全不选</button>
<button>反选</button>
<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">
// 全选
$(‘button‘).eq(0).click(function(){
$(‘input‘).attr(‘checked‘,true);
});
// 全不选
$(‘button‘).eq(1).click(function(){
$(‘input‘).attr(‘checked‘,false);
});
// 反选
$(‘button‘).eq(2).click(function(){
$(‘input‘).each(function(){
this.checked=!this.checked;
});
});
</script>
</html>
技术分享图片

使用jQuery实现全选、全不选、 反选(button)

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

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