for(var i=0;i<document.all.length;i++){if(document.all(i).type == 'text' && document.all(i).value == '') }

解决方案 »

  1.   


    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>hehe</title>
    <SCRIPT language=javascript>function check(){
    for(var i=0;i<document.all.length;i++)

    {
    if(document.all(i).type == 'text' && document.all(i).value == '')
    alert("为空");
     }
    } </SCRIPT>
    </head>
    <body topmargin="0" leftmargin="0">
    <form name="form1" method="post" action="" onSubmit="return check()">
      <input type="text" name="textfield">
      <input type="text" name="textfield2">
      <input type="text" name="textfield3">
      <input type="submit" name="Submit" value="提交">
    </form>
    </body>
    </html>
      

  2.   

    function checkSubmit()
    {
    var Dates = "1234567890";
    for(i=0;i<document.form1.rand.value.length;i++)
    {
    var CheckChar = document.form1.rand.value.charAt(i);
    if(Dates.indexOf(CheckChar)==-1)
    {
    alert("验证码必须是数字!");
    return false;
    }
    }
    if((document.form1.ti.value)==''||(document.form1.ti.value)==null)
    {
    window.alert("标题不能为空!");
    document.form1.ti.select();
    document.form1.ti.focus();
    return false;
    }
    if((document.form1.co.value)==''||(document.form1.co.value)==null)
    {
    window.alert("内容不能为空!");
    document.form1.co.select();
    document.form1.co.focus();
    return false;
    }
    if((document.form1.rand.value)==''||(document.form1.rand.value)==null)
    {
    window.alert("验证码不能为空!");
    document.form1.rand.select();
    document.form1.rand.focus();
    return false;
    }return true;
    }
    这个给你我以前写的 对你可能有用 改一下就行了
      

  3.   

    你是要学习吗?那我不凑热闹了。如果是实际使用我倒是写有一个专门用于判断form提交的文件。使用很方便。
      

  4.   

    楼上的可以发给我吗??你的判断form的文件,我想学学,谢谢~~
      

  5.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>New Page 2</title>
    </head><body>
    <form name=frm>
    input1 **<input altStr="input1 description" ><br>
    input2 **<input altStr="input2 description" ><br>
    input3 **<input altStr="input3 description " ><br>
    input4 **<input altStr="input4 description" ><br>
    input5<input ><br>
    input6<input ><br>
    <input type=button value=test onclick="checkAllNecessaryInputs(this.form);"><br>
    </form>
    </body></html>
    <script>
    function checkAllNecessaryInputs(formObj)
    {
    if(formObj==null) formObj=document.forms[0];
    var theElementsOfTheForm=formObj.elements;
    for (var i=0;i<theElementsOfTheForm.length;i++)
    {
    if((theElementsOfTheForm[i].altStr!=null)
    &&(theElementsOfTheForm[i].altStr!="")
    &&(theElementsOfTheForm[i].value=="")
    )
    {
    alert("Please input :"+ theElementsOfTheForm[i].altStr);
    theElementsOfTheForm[i].focus();
    return false;
    }
    }
    return true;
    }
    </script>