有很多组多选框(一组4个) 判断每组只能选一个的脚本怎么写 求指教

解决方案 »

  1.   

    i = 0;
    cs=document.getElementsByName("name1")
    for(m=0;m<cs.length;m++)
    {
    if(cs[m].checked) i++;
    }
    if(i>1)
    {
    alert("只能 one")
    }
      

  2.   

    checkbox怎么调用啊
    <asp:CheckBox ID="CheckBox1" runat="server" Text=' <%#Eval("Answer") %>'>
    哪个属性调用的?
      

  3.   

    成组的复选框应该用CheckBoxLsit控件啊
      

  4.   

    例子
    <%@ Page Language="C#" %><!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 id="Head1" runat="server">
      <title></title>  <script>
        function chk() {
          for (i = 1; i < 4; i++) {
            cs = document.getElementById("CheckBoxList" + i).getElementsByTagName("input")
            j = 0;
            for (m = 0; m < cs.length; m++) {
              if (cs[m].checked) j++;
            }
            if (j > 1) {
              alert("CheckBoxList" + i + " 只能 选一个");
            }
          }
        }
      </script></head>
    <body>
      <form id="form1" runat="server">
      <asp:CheckBoxList ID="CheckBoxList1" runat="server" RepeatDirection="Horizontal"
        RepeatLayout="Flow">
        <asp:ListItem>A</asp:ListItem>
        <asp:ListItem>B</asp:ListItem>
        <asp:ListItem>C</asp:ListItem>
      </asp:CheckBoxList>
      <br />
      <asp:CheckBoxList ID="CheckBoxList2" runat="server" RepeatDirection="Horizontal"
        RepeatLayout="Flow">
        <asp:ListItem>AA</asp:ListItem>
        <asp:ListItem>BB</asp:ListItem>
        <asp:ListItem>CC</asp:ListItem>
      </asp:CheckBoxList>
      <br />
      <asp:CheckBoxList ID="CheckBoxList3" runat="server" RepeatDirection="Horizontal"
        RepeatLayout="Flow">
        <asp:ListItem>AA</asp:ListItem>
        <asp:ListItem>BB</asp:ListItem>
        <asp:ListItem>CC</asp:ListItem>
      </asp:CheckBoxList>
      <input type="button" value="check" onclick="chk()" />
      </form>
    </body>
    </html>