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>

原创文章,作者:投稿专员,如若转载,请注明出处:https://www.506064.com/n/230929.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
投稿专员投稿专员
上一篇 2024-12-10 18:44
下一篇 2024-12-10 18:44

相关推荐

发表回复

登录后才能评论