<
script
language
=Javascript
>
function a(){
var aa = document.getElementsByTagName( " input " )
for ( var i = 0 ; i < aa.length; i ++ )
{ var aname = aa[i].name;
var value = aa[i].value
var reg =/^ [TextBox_] + [ 0 - 9A - Za - z] + $ / ;
var patrn =/^ d$ / ;
if (aa[i].type == " text " && reg.test(aname) &&! patrn.test(value)){
alert( '' + aname + ' 不能为空且必须是数字 ' );
aa[i].focus();
// 这样已经遍历所有的文本框
}
}
return true
}
</ script >
< form name ="form1" method ="post" action ="" >
< input name ="TextBox_a" type ="text" id ="TextBox_a" />
< input name ="TextBox_88" type ="text" id ="TextBox_88" />
< input name ="NOTextBox_ee" type ="text" id ="NOTextBox_ee" />
< input name ="TextBox_dd" type ="text" id ="TextBox_dd" />
< input name ="1TextBox_dd" type ="text" id ="1TextBox_dd" />
< input type ="button" id ="Button2" value ="录入" onClick ="a()" >
</ form >
function a(){
var aa = document.getElementsByTagName( " input " )
for ( var i = 0 ; i < aa.length; i ++ )
{ var aname = aa[i].name;
var value = aa[i].value
var reg =/^ [TextBox_] + [ 0 - 9A - Za - z] + $ / ;
var patrn =/^ d$ / ;
if (aa[i].type == " text " && reg.test(aname) &&! patrn.test(value)){
alert( '' + aname + ' 不能为空且必须是数字 ' );
aa[i].focus();
// 这样已经遍历所有的文本框
}
}
return true
}
</ script >
< form name ="form1" method ="post" action ="" >
< input name ="TextBox_a" type ="text" id ="TextBox_a" />
< input name ="TextBox_88" type ="text" id ="TextBox_88" />
< input name ="NOTextBox_ee" type ="text" id ="NOTextBox_ee" />
< input name ="TextBox_dd" type ="text" id ="TextBox_dd" />
< input name ="1TextBox_dd" type ="text" id ="1TextBox_dd" />
< input type ="button" id ="Button2" value ="录入" onClick ="a()" >
</ form >