建议换成4组radio,就不用判断了

解决方案 »

  1.   

    相同的问题在:
    http://community.csdn.net/Expert/topic/3624/3624821.xml?temp=.7933771
      

  2.   

    function fnc3(strid,obj)
      {
        
        if(obj.checked)
        {
        bname=obj.name
        bname=bname.substr(0,bname.length-1)
        for(i=1;i<=4;i++)
         if (i!=strid)
         document.all(bname +(i-1)).checked=false;
        }
      }
      

  3.   

    function fnc()
    {
    for(var i=1;i<5;i++)
    for(var j=0;j<4;j++)
    {
    var obj=document.all("Repeater1__ctl1"+i+"_CheckBox"+j);
    if(obj.checked)
    return true;
    }
    alert("不能全为空!")
    return false;
    }
      

  4.   

    <script language="javascript">
    function fnc()
    {
    for(var i=1;i<5;i++)
    for(var j=0;j<4;j++)
    {
    var obj=document.all("Repeater1__ctl1"+i+"_CheckBox"+j);
    if(obj.checked)
    return true;
    }
    alert("不能全为空!")
    return false;
    }function fnc3(strid,obj)
    {
    if(obj.checked)
    {
    bname=obj.name
    bname=bname.substr(0,bname.length-1)
    for(i=1;i<=4;i++)
    if (i!=strid)
    document.all(bname +(i-1)).checked=false;
    }
    }
    function login_check()
    {
    if(fnc==false)
    return false
    if(document.Form1.Text_User_Identification.value=="" || document.Form1.Text_User_Mobile.value=="")
    {
    alert("身份证号和手机号至少需要填写一处!!!");
    return false;
    }
    return true
    }
    </script>
    ....
    <form name=Form1 method="post" onsubmit="return login_check">
      

  5.   

    <form name=Form1 method="post" onsubmit="return login_check()">
      

  6.   

    李兄。这样做感觉麻烦了。。
    能否代用控件所在单元格id来操作
    思路如下:其中strid是从1到4
    function fnc3(strid,obj)
      {
        for(var i=0;i<document.all.length;i++)
        {
          if(document.all(i).type == 'checkbox' && document.all(i).parentElement.id == strid) document.all(i).checked = false;obj.checked=true;
        }
      }
      

  7.   

    李兄用你的这个方法不能实现我的要求。我要求的是每列至少选择一个checkbox也只能选择一个。就是不能全为空。。
    但是用你的方法只要4列中任选择了一个就不提示了错误了。应该是4列中至少每列选择了一个checkbox
      

  8.   

    思路:设一个计数器,记录每列复选框的数目,记得在外层循环中清0
    function fnc()
              {
               var n=0;//计数器
               for(var j=1;j<5;j++)
               {
                 for(var i=0;i<document.all.length;i++)
                  {
                    if(document.all(i).type == 'checkbox' && document.all(i).parentElement.id == j.toString() && document.parentElement.all(i).checked == true) 
                       {
                         n++;
                       }       
                }
                  if(n==0)
                           {
                            alert("每列至少要选择一个"); return false;
                   }
                else
                  {
             n=0;
                               //return true;
                  }           }
      

  9.   

    zhuqm(东子)兄台:
    出错提示:
    document.parentElement为空或不是对象
      

  10.   

    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=gb2312">
    <title> 站点发布信息</title>
    </head>
    <script language="javascript">
      function fnc()
              {
               for(var j=1;j<5;j++)
               {
                 for(var i=0;i<document.all.length;i++)
                  {
                    if(document.all(i).type == 'checkbox' && document.all(i).parentElement.id == j.toString() && document.all(i).parentElement.id.checked == false)
                       {
                         alert("sdfasdf"); return false;
                   }
                else
                  {
                return true;
                  }
                   }       
                }
               }
      function fnc3(strid,obj)
      {
        for(var i=0;i<document.all.length;i++)
        {
          if(document.all(i).type == 'checkbox' && document.all(i).parentElement.id == strid) document.all(i).checked = false;obj.checked=true;
        }
      }
     
    function login_check() 

        if(!checknotnull()) return false;
       if(document.Form1.Text_User_Identification.value!="" || document.Form1.Text_User_Mobile.value!="") 
        {
        return true;
        }
        else
        {
       alert("身份证号和手机号至少需要填写一处!!!");  return false;
        }
      }
      function checknotnull()
      {

    for(var i=0;i<4;i++)
    {
    var count= 0;
    for(var j=1;j<5;j++)
    {
    var obj=eval(document.forms[0].elements["Repeater1__ctl1"+j+"_Checkbox"+i]);
    if(obj.checked) count=count+1;
    }
    if(count==0)
    {
    alert("空!"+i+"@");
    return false;
    }
    }

    return true;
      }

       </script>
    <body>
    <FORM METHOD=POST ACTION="">
    <TABLE id="Table2" cellSpacing="0" cellPadding="0" width="80%" align="center" border="0">
    <TR>
    <TD width="15%" align="right">HP</TD>
    <td width="10%" id="1" align="center"><input name="Repeater1:_ctl11:SelectedID" id="Repeater1__ctl11_SelectedID" type="hidden" value="11" />
    <input name="Repeater1:_ctl11:CheckBox0" id="Repeater1__ctl11_Checkbox0" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">HP</TD>
    <td width="10%" id="2" align="center">
    <input name="Repeater1:_ctl11:Checkbox1" id="Repeater1__ctl11_Checkbox1" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">HP</TD>
    <td width="10%" id="3" align="center">
    <input name="Repeater1:_ctl11:Checkbox2" id="Repeater1__ctl11_Checkbox2" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">HP</TD>
    <td width="10%" id="4" align="center">
    <input name="Repeater1:_ctl11:Checkbox3" id="Repeater1__ctl11_Checkbox3" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    </TR>

    <TR>
    <TD width="15%" align="right">金利</TD>
    <td width="10%" id="1" align="center"><input name="Repeater1:_ctl12:SelectedID" id="Repeater1__ctl12_SelectedID" type="hidden" value="12" />
    <input name="Repeater1:_ctl12:CheckBox0" id="Repeater1__ctl12_Checkbox0" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">金利</TD>
    <td width="10%" id="2" align="center">
    <input name="Repeater1:_ctl12:Checkbox1" id="Repeater1__ctl12_Checkbox1" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">金利</TD>
    <td width="10%" id="3" align="center">
    <input name="Repeater1:_ctl12:Checkbox2" id="Repeater1__ctl12_Checkbox2" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">金利</TD>
    <td width="10%" id="4" align="center">
    <input name="Repeater1:_ctl12:Checkbox3" id="Repeater1__ctl12_Checkbox3" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    </TR>

    <TR>
    <TD width="15%" align="right">新蓝</TD>
    <td width="10%" id="1" align="center"><input name="Repeater1:_ctl13:SelectedID" id="Repeater1__ctl13_SelectedID" type="hidden" value="13" />
    <input name="Repeater1:_ctl13:CheckBox0" id="Repeater1__ctl13_Checkbox0" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">新蓝</TD>
    <td width="10%" id="2" align="center">
    <input name="Repeater1:_ctl13:Checkbox1" id="Repeater1__ctl13_Checkbox1" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">新蓝</TD>
    <td width="10%" id="3" align="center">
    <input name="Repeater1:_ctl13:Checkbox2" id="Repeater1__ctl13_Checkbox2" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">新蓝</TD>
    <td width="10%" id="4" align="center">
    <input name="Repeater1:_ctl13:Checkbox3" id="Repeater1__ctl13_Checkbox3" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    </TR>

    <TR>
    <TD width="15%" align="right">百时通</TD>
    <td width="10%" id="1" align="center"><input name="Repeater1:_ctl14:SelectedID" id="Repeater1__ctl14_SelectedID" type="hidden" value="14" />
    <input name="Repeater1:_ctl14:CheckBox0" id="Repeater1__ctl14_Checkbox0" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">百时通</TD>
    <td width="10%" id="2" align="center">
    <input name="Repeater1:_ctl14:Checkbox1" id="Repeater1__ctl14_Checkbox1" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">百时通</TD>
    <td width="10%" id="3" align="center">
    <input name="Repeater1:_ctl14:Checkbox2" id="Repeater1__ctl14_Checkbox2" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    <TD width="15%" align="right">百时通</TD>
    <td width="10%" id="4" align="center">
    <input name="Repeater1:_ctl14:Checkbox3" id="Repeater1__ctl14_Checkbox3" type="checkbox" onclick="fnc3(this.parentElement.id,this);" /></td>
    </TR>

    </TABLE>
    <INPUT TYPE="button" name="test" value="测试" onclick="return login_check()">
    </FORM>
    </body>
    </html>注意  你的程序的Repeater1:_ctl11:CheckBox0 中的 B 要改成小写b Repeater1:_ctl11:Checkbox0
      

  11.   

    有什么简单的办法能读取id相同的每列的checkbox的个数吗
      

  12.   

    比如说一行里的4列如下:<td width="10%" id="1" align="center">
    <TR>
    <td width="10%" id="1" align="center">
    <td width="10%" id="2" align="center">
    <td width="10%" id="3" align="center">
    <td width="10%" id="4" align="center">
    </TR>
      

  13.   

    有什么简单的办法能读取id相同的每列的checkbox的个数吗
    比如说一行里的4列如下:<td width="10%" id="1" align="center">
    <TR>
    <td width="10%" id="1" align="center">
    <td width="10%" id="2" align="center">
    <td width="10%" id="3" align="center">
    <td width="10%" id="4" align="center">
    </TR>
      

  14.   

    有什么简单的办法能读取id相同的每列的checkbox的个数吗
    比如说一行里的4列如下:<td width="10%" id="1" align="center">
    <TR>
    <td width="10%" id="1" align="center">
    <td width="10%" id="2" align="center">
    <td width="10%" id="3" align="center">
    <td width="10%" id="4" align="center">
    </TR>
      

  15.   

    有什么简单的办法能读取id相同的每列的checkbox的个数吗
    比如说一行里的4列如下:<td width="10%" id="1" align="center">
    <TR>
    <td width="10%" id="1" align="center">
    <td width="10%" id="2" align="center">
    <td width="10%" id="3" align="center">
    <td width="10%" id="4" align="center">
    </TR>