for(var i=0; i<document.formName.elements.length; i++)
{
  if(document.formName.elements[i].value=="")
  {
    //............../
  }
}

解决方案 »

  1.   

    <form name=aaa>
    StudentName01<input altStr="StudentName01" >*<br>
    StudentName01<input altStr="StudentName02" >*<br>
    StudentName01<input altStr="StudentName03" >*<br>
    StudentName01<input altStr="StudentName04" >*<br>
    StudentName01<input altStr="StudentName05" >*<br>
    StudentName01<input altStr="StudentName06" >*<br>
    StudentName01<input ><br>
    StudentName01<input ><br>
    StudentName01<input ><br><input type=button value=checkAllNecessaryInputs onclick="checkAllNecessaryInputs(document.forms['aaa']);">
    </form>
    <script>
    /**
    * This function is to get if all necessary inputs have been inputted.
    * Please give the NecessaryInput a property named "altStr".This property will be alert when it has not been inputed.
    * For Example, 
    *   This is a necessary input:<input altStr="Name">
    *   This is not a necessary input:<input altStr="Name">
    * JK 2003-12-08
    */
    function checkAllNecessaryInputs(formObj)
    {
    var theFirstNecessaryInputToBeFilled=null;//Get it to focus;
    var theAlertStr="";
    var theNumOfInputsToBeFilled=0;

    var theElementsOfTheForm=formObj.elements;
    for (var i=0;i<theElementsOfTheForm.length;i++)
    {
    if(theNumOfInputsToBeFilled>9) break;
    if((theElementsOfTheForm[i].altStr!=null)
    &&(theElementsOfTheForm[i].altStr!="")
    &&(theElementsOfTheForm[i].value=="")
    )
    {
    theNumOfInputsToBeFilled++;
    theAlertStr=theAlertStr+"\n"+theElementsOfTheForm[i].altStr;
    if(theFirstNecessaryInputToBeFilled==null)
    theFirstNecessaryInputToBeFilled=theElementsOfTheForm[i];
    }
    }
    if(theNumOfInputsToBeFilled>0)
    {
    alert("Please input :"+ theAlertStr);
    theFirstNecessaryInputToBeFilled.focus();
    return false;
    }
    return true;
    }
    </script>