jquery实现全选和取消全选(jquery全选反选操作)


<!doctype html>

<html>

<head>

<meta charset=”UTF-8″>

<title>Document</title>

<script type=”text/javascript” src=”jquery.min.js”></script>

</head>

<body>

<input type=”checkbox” id=”checkbox1″><label for=”checkbox1″>库里</label><br>

<input type=”checkbox” id=”checkbox2″><label for=”checkbox2″>科比</label><br>

<input type=”checkbox” id=”checkbox3″><label for=”checkbox3″>麦迪</label><br>

<input type=”checkbox” id=”checkbox4″><label for=”checkbox4″>邓肯</label><br>

<input type=”checkbox” id=”checkbox5″><label for=”checkbox5″>奥尼尔</label><br><br>

<button>全选</button><button>全不选</button><button>反选</button>

</body>

</html>

<script type=”text/javascript”>

$(function(){

//匹配第一个button

$(‘:button:eq(0)’).click(function(){

//全部选中 checked=true,在前台就是表示选中

$(‘:checkbox’).attr(‘checked’,true);

});

//匹配第二个button

$(‘:button:eq(1)’).click(function(){

//全部取消 checked=false,在前台就是表示未选中

$(‘:checkbox’).attr(‘checked’,false);

});

//匹配第三个button

$(‘:button:eq(2)’).click(function(){

//查找每一个复选框,然后取相反

$(‘:checkbox’).each(function(){

$(this).attr(‘checked’,!$(this).attr(‘checked’));

});

});

})

</script>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发表评论

登录后才能评论