你的分享就是我们的动力 ---﹥

JS遍历页面上的checkbox

时间:2011-10-26 09:55来源:www.chengxuyuans.com 点击:

分享一个JS遍历checkbox代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">  
  protected void Button1_Click(object sender, EventArgs e)
  {
    FindBox(this.Controls);
  }

  private void FindBox(ControlCollection cc)
  {
  foreach (Control c in cc)
  {
    if (c.HasControls())
    {
      FindBox(c.Controls);
    }
    if (c is CheckBox)
    {
      CheckBox x = c as CheckBox;
      //判断名称
      if (x.Attributes["name"] != null && x.Attributes["name"].Equals("Admin_Power"))
        {
          Response.Write("<li>" + x.Attributes["name"]);
        }
    }
   }
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
</head>
<body>
  <form runat="server" id="form1">
  <asp:CheckBox ID="CheckBox7" runat="server" name="xxxxx" Text=" xxxxx" />
  <asp:CheckBox ID="CheckBox1" runat="server" name="Admin_Power" Text=" 投票1" />
  <asp:CheckBox ID="CheckBox2" runat="server" name="Admin_Power" Text=" 投票2" />
  <asp:CheckBox ID="CheckBox3" runat="server" name="Admin_Power" Text=" 投票3" />
  <asp:CheckBox ID="CheckBox4" runat="server" name="Admin_Power" Text=" 投票4" />
  <asp:CheckBox ID="CheckBox5" runat="server" name="Admin_Power" Text=" 投票5" />
  <asp:CheckBox ID="CheckBox6" runat="server" name="Admin_Power" Text=" 投票6" />
  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="得到" />
  </form>
</body>
</html>

转载注明地址:http://www.chengxuyuans.com/css/28814.html