不要用txt1,txt2了,。。都用同一个名txt,你的代码对了

解决方案 »

  1.   

    谢谢2楼!如果这十个文本框一定要用txt1、txt2……txt10命名呢?
      

  2.   

    <script language="JavaScript">
    <!--
    function chehkForm(form)
    {
    alert(form.elements[0].value);
    for(var i=0; i < 3; i++)
    {
    if(form.elements[i].value == "")
    {
    alert(form.elements[i].name + " 不能为空!");
    return false;
    }
    }
    }
    //-->
    </script>
    <form method=post action="" onsubmit="chehkForm(this)">
    <table align=center width="100%" cellspacing=0 cellpadding=0 border=0 >
    <tr>
    <td height="200" align="center" bgcolor="#EEEEEE">
    <input type="text" name="t1"><input type="text" name="t2"><input type="text" name="t3">
    <br><input type="submit">
    </td>
    </tr>
    </table>
    </form>
      

  3.   

    把这句注释掉 alert(form.elements[0].value); 测试时写上去的忘了去掉。
      

  4.   

    if (form.txt[i].value=="" )---->if(eval('form.txt'+i).value=='')
      

  5.   

    function check()      
    {
    for (var i=1;i<11;i++){
    if (eval("form.txt"+i+".value==''"))
    {
    alert('txt'+ i + "数值为空,请确认')
    return false;
    }

    }
    }