asp.net复选框的全选全不选功能的实现asp:checkbox

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>


<!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>
    <link rel="stylesheet" type="text/css" href="../css/Frame.css" />
    <link rel="stylesheet" type="text/css" href="../css/BackgroundTwo.css" />
</head>
<SCRIPT language=javascript>
<!-- 全选 -->
function selectall(v){
  var f = document.form1;
  for (i=0;i<f.elements.length;i++)
     f.elements[i].checked = v;
  document.form1.elements["CheckBox13"].checked = v;
}

<!-- 改变选择列的颜色 -->
function changechecked(checkbut){
 var v =checkbut.checked;
 
 if (v) {
     checkbut.checked = true;
     if(isallselected()){
      document.form1.elements["CheckBox13"].checked = true;
     }
    }else{
     document.form1.elements["CheckBox13"].checked = false;
     checkbut.checked = false;
    }
}

<!-- 是否有选中? -->
function isselected(){
  var f = document.form1;
  for (i=0;i<f.elements.length;i++)
    if ((f.elements[i].name=="CheckBox13") && (f.elements[i].checked)) return true;
  return false;
}

<!--是否全部选中? -->
function isallselected(){
 var selectcount = 0;
 var allcount=0;
 
 var f=document.form1;

for(i=0;i<f.elements.length;i++){
  if(f.elements[i].type=="checkbox"&&f.elements[i].id!="CheckBox13")
  if (f.elements[i].checked!=true){
    alert(f.elements[i].id);
   return false;
  }
 }
  return true;

}


</SCRIPT>

<body>
    <form id="form1" runat="server" >
    <div>


   
   
        <asp:CheckBox ID="CheckBox13" runat="server" onclick="selectall(this.checked)" />全选<br />
        <asp:CheckBox ID="CheckBox1" runat="server" />有效期:<input runat="server" id="txt_yxq" type="text" />
        <asp:CheckBox ID="CheckBox2" runat="server" onclick=changechecked(this) />违法性质:
        <asp:TextBox ID="txt_wfxz" runat="server"></asp:TextBox><br />
        <asp:CheckBox ID="CheckBox3" runat="server" onclick=changechecked(this) />号牌种类:<asp:DropDownList ID="DropDownList2"
            runat="server">
        </asp:DropDownList>
        <asp:CheckBox ID="CheckBox4" runat="server" onclick=changechecked(this) />号牌号码:
        <asp:TextBox ID="txt_hphm" runat="server"></asp:TextBox><br />
        <asp:CheckBox ID="CheckBox5" runat="server" onclick=changechecked(this) />违法类型:<asp:DropDownList ID="DropDownList3"
            runat="server">
        </asp:DropDownList>
        <asp:CheckBox ID="CheckBox6" runat="server" onclick=changechecked(this) />发动机号:
        <asp:TextBox ID="txt_fdjh" runat="server"></asp:TextBox><br />
        <asp:CheckBox ID="CheckBox7" runat="server" onclick=changechecked(this) />车辆品牌:<asp:TextBox ID="txt_clpp" runat="server"></asp:TextBox>
        <asp:CheckBox ID="CheckBox8" runat="server" onclick=changechecked(this) />车驾号:
        <asp:TextBox ID="txt_cjh" runat="server"></asp:TextBox><br />
        <asp:CheckBox ID="CheckBox9" runat="server" onclick=changechecked(this) />所有人:<asp:TextBox ID="txt_syr" runat="server"></asp:TextBox>
        <asp:CheckBox ID="CheckBox10" runat="server" onclick=changechecked(this) />车辆类型:<asp:DropDownList ID="DropDownList4"
            runat="server">
        </asp:DropDownList><br />
        <asp:CheckBox ID="CheckBox11" runat="server" onclick=changechecked(this) />车身颜色:<asp:DropDownList ID="DropDownList5"
            runat="server">
        </asp:DropDownList>
        <asp:DropDownList ID="DropDownList6" runat="server">
        </asp:DropDownList><br />
        <asp:CheckBox ID="CheckBox12" runat="server" onclick=changechecked(this) />备注:<br />
        <asp:TextBox ID="txt_bz" runat="server" Height="125px" TextMode="MultiLine" Width="402px"></asp:TextBox><br /><br />
       
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        <input id="insert" runat="server" type="submit" value="加入黑名单列表" onserverclick="insert_ServerClick" /><br />
        <br />
         动态下拉:
       
        <asp:DropDownList ID="DropDownList1" runat="server" >
        </asp:DropDownList>
       
       
        </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><title>
 无标题页
</title><link rel="stylesheet" type="text/css" href="../css/Frame.css" /><link rel="stylesheet" type="text/css" href="../css/BackgroundTwo.css" /></head>
<SCRIPT language=javascript>
<!-- 全选 -->
function selectall(v){
  var f = document.form1;
  for (i=0;i<f.elements.length;i++)
     f.elements[i].checked = v;
  document.form1.elements["CheckBox13"].checked = v;
}

<!-- 改变选择列的颜色 -->
function changechecked(checkbut){
 var v =checkbut.checked;
 
 if (v) {
     checkbut.checked = true;
     if(isallselected()){
      document.form1.elements["CheckBox13"].checked = true;
     }
    }else{
     document.form1.elements["CheckBox13"].checked = false;
     checkbut.checked = false;
    }
}

<!-- 是否有选中? -->
function isselected(){
  var f = document.form1;
  for (i=0;i<f.elements.length;i++)
    if ((f.elements[i].name=="CheckBox13") && (f.elements[i].checked)) return true;
  return false;
}

<!--是否全部选中? -->
function isallselected(){
 var selectcount = 0;
 var allcount=0;
 
 var f=document.form1;

for(i=0;i<f.elements.length;i++){
  if(f.elements[i].type=="checkbox"&&f.elements[i].id!="CheckBox13")
  if (f.elements[i].checked!=true){
    alert(f.elements[i].id);
   return false;
  }
 }
  return true;

 
 
 
 
 
  

}


</SCRIPT>

<body>
    <form name="form1" method="post" action="Register.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTM3OTUyNTM4NA9kFgICAw9kFgICOQ8QDxYGHg1EYXRhVGV4dEZpZWxkBQNkbXoeDkRhdGFWYWx1ZUZpZWxkBQNkbXoeC18hRGF0YUJvdW5kZ2QQFQkCYWECYWICYWMCYWQCYWUCYWYCYWcCYWgCYWkVCQJhYQJhYgJhYwJhZAJhZQJhZgJhZwJhaAJhaRQrAwlnZ2dnZ2dnZ2dkZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WDQUKQ2hlY2tCb3gxMwUJQ2hlY2tCb3gxBQlDaGVja0JveDIFCUNoZWNrQm94MwUJQ2hlY2tCb3g0BQlDaGVja0JveDUFCUNoZWNrQm94NgUJQ2hlY2tCb3g3BQlDaGVja0JveDgFCUNoZWNrQm94OQUKQ2hlY2tCb3gxMAUKQ2hlY2tCb3gxMQUKQ2hlY2tCb3gxMh2SM5uEghFLMH6ZQJD7lmvfNIfk" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
// -->
</script>


    <div>


   
   
        <input id="CheckBox13" type="checkbox" name="CheckBox13" onclick="selectall(this.checked);" />全选<br />
        <input id="CheckBox1" type="checkbox" name="CheckBox1" />有效期:<input name="txt_yxq" type="text" id="txt_yxq" />
        <input id="CheckBox2" type="checkbox" name="CheckBox2" onclick="changechecked(this);" />违法性质:
        <input name="txt_wfxz" type="text" id="txt_wfxz" /><br />
        <input id="CheckBox3" type="checkbox" name="CheckBox3" onclick="changechecked(this);" />号牌种类:<select name="DropDownList2" id="DropDownList2">

</select>
        <input id="CheckBox4" type="checkbox" name="CheckBox4" onclick="changechecked(this);" />号牌号码:
        <input name="txt_hphm" type="text" id="txt_hphm" /><br />
        <input id="CheckBox5" type="checkbox" name="CheckBox5" onclick="changechecked(this);" />违法类型:<select name="DropDownList3" id="DropDownList3">

</select>
        <input id="CheckBox6" type="checkbox" name="CheckBox6" onclick="changechecked(this);" />发动机号:
        <input name="txt_fdjh" type="text" id="txt_fdjh" /><br />
        <input id="CheckBox7" type="checkbox" name="CheckBox7" onclick="changechecked(this);" />车辆品牌:<input name="txt_clpp" type="text" id="txt_clpp" />
        <input id="CheckBox8" type="checkbox" name="CheckBox8" onclick="changechecked(this);" />车驾号:
        <input name="txt_cjh" type="text" id="txt_cjh" /><br />
        <input id="CheckBox9" type="checkbox" name="CheckBox9" onclick="changechecked(this);" />所有人:<input name="txt_syr" type="text" id="txt_syr" />
        <input id="CheckBox10" type="checkbox" name="CheckBox10" onclick="changechecked(this);" />车辆类型:<select name="DropDownList4" id="DropDownList4">

</select><br />
        <input id="CheckBox11" type="checkbox" name="CheckBox11" onclick="changechecked(this);" />车身颜色:<select name="DropDownList5" id="DropDownList5">

</select>
        <select name="DropDownList6" id="DropDownList6">

</select><br />
        <input id="CheckBox12" type="checkbox" name="CheckBox12" onclick="changechecked(this);" />备注:<br />
        <textarea name="txt_bz" rows="2" cols="20" id="txt_bz" style="height:125px;width:402px;"></textarea><br /><br />
       
        <span id="Label1">Label</span>

        <input name="insert" type="submit" id="insert" value="加入黑名单列表" /><br />
        <br />
         动态下拉:
       
        <select name="DropDownList1" id="DropDownList1">
 <option value="aa">aa</option>
 <option value="ab">ab</option>
 <option value="ac">ac</option>
 <option value="ad">ad</option>
 <option value="ae">ae</option>
 <option value="af">af</option>
 <option value="ag">ag</option>
 <option value="ah">ah</option>
 <option value="ai">ai</option>

</select>
       
       
        </div>
   
<div>

 <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWIAKA18KbCgKC5JO8CQKC5Ne7CQKIlpbICQL/49e7CQLT9uauCQKA5Ne7CQL949e7CQLmiaC+BgL+49e7CQL749e7CQK+t/jbDQL849e7CQLnrOiUDwL549e7CQLvifywAwL649e7CQLB2sCICwKC5Je8CQKC5Ju8CQKC5I+8CQKK+7b4BgKakYGXBgKii6mKBgKii62KBgKii5GKBgKii5WKBgKii5mKBgKii52KBgKii4GKBgKii8WKBgKii8mKBmJ+9uRqJBP2GirYNTJxv1XRnWuD" />
</div></form>
</body>
</html>

 

黑色头发  http://heisetoufa.iteye.com

你可能感兴趣的:(.net,css,F#,asp.net,asp)