jquery全选反选

View Code
<head>
<title></title>

<script src="js/jquery-1.4.2.js" type="text/javascript"></script>

<script type="text/javascript">
$(
function() {
$(
"#selall").click(function() { //取得id为aaa的标签下面的类型为chexkbox的控件。 $("#aaa :checkbox").attr("checked", true);// 将其checked属性实质为true
});
});
$(
function() {
$(
"#noselall").click(function() { //取得id为aaa的标签下面的类型为chexkbox的控件。
$("#aaa :checkbox").attr("checked", false); // 将其checked属性实质为false
});
});
$(
function() {
$(
"#reverse").click(function() { //取得id为reserse的控件
$("#aaa :checkbox").each(function() { //遍历其类型为checkbox的空间
$(this).attr("checked",!$(this).attr("checked"))//将选择的取消,取消的选择
});
});
});
</script>

</head>
<body>
<div id="aaa">
<input type="checkbox"/>歌曲一<br />
<input type="checkbox"/>歌曲二<br />
<input type="checkbox"/>歌曲三<br />
<input type="checkbox"/>歌曲四<br />
</div>
<input id="selall" type="button" value="全选"/>
<input id="noselall" type="button" value="全部选"/>
<input id="reverse" type="button" value="反选"/>
</body>
原文地址:https://www.cnblogs.com/happygx/p/1982054.html