<script>
function checkFrm()
{
var i=0;
for (i=0;i<document.all("chkName").length;i++)
{
if (document.all.chkName[i].checked)
{
if (document.all.txtName1[i].value=='')
{
alert('文本框1数据为空');
return false;
}
if (document.all.txtName2[i].value=='')
{
alert('文本框2数据为空');
return false;
}
}
}
if (document.all("chkName").length>0)
{
document.all.frmName.submit();
return true;
}
else
return false;
}
</script><form method=post action ='' id=frmName>
<input type=checkbox id=chkName>文本框1<input type=text id=txtName1>文本框2<input type=text id=txtName2><br>
<input type=checkbox id=chkName>文本框1<input type=text id=txtName1>文本框2<input type=text id=txtName2><br>
<input type=checkbox id=chkName>文本框1<input type=text id=txtName1>文本框2<input type=text id=txtName2><br>
<input type=checkbox id=chkName>文本框1<input type=text id=txtName1>文本框2<input type=text id=txtName2><br>
<input type=checkbox id=chkName>文本框1<input type=text id=txtName1>文本框2<input type=text id=txtName2><br>
<input type=button value="提交" onclick="checkFrm();">
</form>

解决方案 »

  1.   

    <script>
    function check(f){
    var n=0
    for(i=0;i<f.chkName.length;i++){
    if(f.chkName[i].checked){n++;for(j=1;j<=2;j++)if(!eval("frmName.txtName"+i+j).value){alert('没填');return false}}
    }
    if(n==0){alert('没选');return false}
    return true
    }
    </script>
    <form method=post action ='1.asp' name=frmName onsubmit="return check(this)">
    <input type=checkbox name=chkName>文本框1<input type=text name=txtName01>文本框2<input type=text name=txtName02><br>
    <input type=checkbox name=chkName>文本框1<input type=text name=txtName11>文本框2<input type=text name=txtName12><br>
    <input type=checkbox name=chkName>文本框1<input type=text name=txtName21>文本框2<input type=text name=txtName22><br>
    <input type=checkbox name=chkName>文本框1<input type=text name=txtName31>文本框2<input type=text name=txtName32><br>
    <input type=checkbox name=chkName>文本框1<input type=text name=txtName41>文本框2<input type=text name=txtName42><br>
    <input type=submit  value="提交">
    </form>