<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="是否全选.aspx.cs" Inherits="Test.TestWebForms.是否全选" %>
<!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 runat="server">
<title></title>
<script src="../JS/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//全选、全不选
$("#selAll").click(function () {
$("input[name=ball]").attr("checked", $(this).attr("checked"));
});
//对checkbox进行单个勾选
$("input[name=ball]").click(function () {
var cnt = 0;
$("input[name=ball]").each(function () {
if ($(this).attr("checked")) {
cnt++;
}
});
//勾选的checkbox数量==?全部checkbox的数量
if (cnt == $("input[name=ball]").length) {
$("#selAll").attr("checked", true);
}
else {
$("#selAll").attr("checked", false);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="playList">
<input type="checkbox" value="全选" id="selAll"/>全选<br />
<input type="checkbox" value="篮球" name="ball"/>篮球<br />
<input type="checkbox" value="足球" name="ball"/>足球<br />
<input type="checkbox" value="排球" name="ball"/>排球<br />
<input type="checkbox" value="冰球" name="ball"/>冰球<br />
</div>
</form>
</body>
</html>
<!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 runat="server">
<title></title>
<script src="../JS/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//全选、全不选
$("#selAll").click(function () {
$("input[name=ball]").attr("checked", $(this).attr("checked"));
});
//对checkbox进行单个勾选
$("input[name=ball]").click(function () {
var cnt = 0;
$("input[name=ball]").each(function () {
if ($(this).attr("checked")) {
cnt++;
}
});
//勾选的checkbox数量==?全部checkbox的数量
if (cnt == $("input[name=ball]").length) {
$("#selAll").attr("checked", true);
}
else {
$("#selAll").attr("checked", false);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="playList">
<input type="checkbox" value="全选" id="selAll"/>全选<br />
<input type="checkbox" value="篮球" name="ball"/>篮球<br />
<input type="checkbox" value="足球" name="ball"/>足球<br />
<input type="checkbox" value="排球" name="ball"/>排球<br />
<input type="checkbox" value="冰球" name="ball"/>冰球<br />
</div>
</form>
</body>
</html>