<script>function aa(){
var b=document.getElementsByTagName("input")
for(var i=0;i<b.length;i++){
   if(b[i].type=="text"){
  if(b[i].name.length>7){
 if(b[i].name.substr(0,7)=="product"){
 alert(b[i].name)
 alert(b[i].value)
 }
  }
   }
}
}
</script>
<input name="product1" type="text" value="" onclick="aa()">
<input name="product2" type="text" value="">
<input name="product3" type="text" value="">
<input name="product4" type="text" value="">

解决方案 »

  1.   

    <input name="product1" altStr="产品1" type="text" value="">
    <input name="product2" altStr="产品2" type="text" value="">
    <input name="product3" altStr="产品3" type="text" value="">
    <input name="product4" altStr="产品4" type="text" value="">
    /**
    * 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 >
    * JK 2003-12-08
    */
    function checkAllNecessaryInputs(formObj)
    {
    if(formObj==null) formObj=document.forms[0];
    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>0) break;
    if((theElementsOfTheForm[i].altStr!=null)
    &&(theElementsOfTheForm[i].altStr!="")
    &&(trim(theElementsOfTheForm[i].value)=="")
    )
    {
    try{theElementsOfTheForm[i].focus();}catch(e){continue;}
    theNumOfInputsToBeFilled++;
    theAlertStr=theAlertStr+" "+theElementsOfTheForm[i].altStr;
    if(theFirstNecessaryInputToBeFilled==null)
    theFirstNecessaryInputToBeFilled=theElementsOfTheForm[i];
    }
    }
    if(theNumOfInputsToBeFilled>0)
    {
    alert("请输入:"+ theAlertStr);
    theFirstNecessaryInputToBeFilled.focus();
    return false;
    }
    return true;
    }
      

  2.   

    <script language="JavaScript">
    function bb(){
    var b=document.getElementsByTagName("input")
    for(var i=0;i<b.length;i++){
    if(b[i].name.substr(0,7)=="product"){
    if(b[i].value==""){
    alert("请产品"+i+"的值。");
    //b[i].name.focus(); 注意这一行
    return (false);
    }
    }
    }
    }
    </script><form name="form1" action="input.asp" onSubmit="bb()">
    <input name="product1" type="text" value="" >
    <input name="product2" type="text" value="">
    <input name="product3" type="text" value="">
    <input name="product4" type="text" value="">
    <input name="rr" type="submit" value="OK">
    </form>看看这里
    alert("请产品"+i+"的值。");
    //b[i].name.focus(); 注意这一行
    return (false);
    如何做到让alert确定后,退出FOR,且焦点落在product[i]中,并且不能提交?
      

  3.   

    <html>
    <head>
    <title>
    dfjk</title>
    </head>
    <body>
    <script language="JavaScript">
    function bb(){
    var b=document.getElementsByTagName("input")
    for(var i=0;i<b.length;i++){
        //这要加上 if(b[i].name.length>7){这个判断,因为别的input的name可能没7个,.substr(0,7)的时候会出错
    if(b[i].name.substr(0,7)=="product"){
    if(b[i].value==""){
    alert("请产品"+(i+1)+"的值。");
    //exit for
    b[i].focus();
    return false;
    }
    }
    }
    return true
    }
    </script><form name="form1" action="input.asp" onSubmit="return bb()">
    <input name="product1" type="text" value="" >
    <input name="product2" type="text" value="">
    <input name="product3" type="text" value="">
    <input name="product4" type="text" value="">
    <input name="rr" type="submit" value="OK">
    </form>
    </body>
    </html>