全选不选反选
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#btn1").click(function () {
$("#div1 input:checkbox").attr("checked", true);
//$("#div1 :checkbox").attr("checked", true);//效果同上,中间要有空格
});
});
$(function () {
$("#btn2").click(function () {
$("#div1 input:checkbox").attr("checked", false);
//$("#div1 :checkbox").attr("checked", false);//效果同上,中间要有空格
});
});
$(function () {
$("#btn3").click(function () {
$("#div1 input:checkbox").each(function () {
$(this).attr("checked",!$(this).attr("checked"));
});
//$("#div1 :checkbox").attr("checked", true);//效果同上,中间要有空格
});
});
</script>
</head>
<body>
<div id="div1">
<input type="checkbox" value="lanqiu" />篮球<br />
<input type="checkbox" value="zuqiu" />足球<br />
<input type="checkbox" value="paiqiu" />排球<br />
<input type="button" id="btn1" value="全选" />
<input type="button" id="btn2" value="不选" />
<input type="button" id="btn3" value="反选" />
</div>
</body>
</html>