javascript全选或全取消页面中的CheckBox
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 type="text/javascript">
function CheckAll(obj){
var form = document.getElementById("form1");
if(obj.checked){
for(var i=0;i<form.elements.length;i++){
if(form.elements[i].type == "checkbox"){
form.elements[i].checked = true;
}
}
}
else{
for(var i=0;i<form.elements.length;i++){
if(form.elements[i].type == "checkbox"){
form.elements[i].checked = false;
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="CheckAll(this)" />全选<br/>
<asp:CheckBox ID="CheckBox2" runat="server" /><br/>
<asp:CheckBox ID="CheckBox3" runat="server" /><br/>
<asp:CheckBox ID="CheckBox4" runat="server" /><br/>
<asp:CheckBox ID="CheckBox5" runat="server" /><br/>
<asp:CheckBox ID="CheckBox6" runat="server" /><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 type="text/javascript">
function CheckAll(obj){
var form = document.getElementById("form1");
if(obj.checked){
for(var i=0;i<form.elements.length;i++){
if(form.elements[i].type == "checkbox"){
form.elements[i].checked = true;
}
}
}
else{
for(var i=0;i<form.elements.length;i++){
if(form.elements[i].type == "checkbox"){
form.elements[i].checked = false;
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="CheckAll(this)" />全选<br/>
<asp:CheckBox ID="CheckBox2" runat="server" /><br/>
<asp:CheckBox ID="CheckBox3" runat="server" /><br/>
<asp:CheckBox ID="CheckBox4" runat="server" /><br/>
<asp:CheckBox ID="CheckBox5" runat="server" /><br/>
<asp:CheckBox ID="CheckBox6" runat="server" /><br/>
</div>
</form>
</body>
</html>