日期:2014-05-17  浏览次数:21360 次

二问:输入框的检测问题,真的有点难,请高手指点.
<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+ "的值。 ");
//exit   for
//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+ "的值。 ");
                                    //exit   for
//b[i].name.focus();   注意这一行
return   (false);
如何做到让alert确定后,退出FOR,且焦点落在product[i]中,并且不能提交?

------解决方案--------------------
<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].focus();
return false;
}
}
}
}
</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>