<!-- #include file="message.inc" --> 2 < HTML > 3 < HEAD > 4 < TITLE > New Document </ TITLE > 5 < meta http-equiv ="content-type" content ="text/html; charset=shift_jis" /> 6 < meta http-equiv ="pragma" content ="no-cache" > 7 < meta http-equiv ="cache-control" content ="no-cache" > 8 < meta http-equiv ="expires" content ="0" > 9 < script src ="common.js" ></ script > 10 < script src ="validate.js" ></ script > 1112 </ HEAD > 1314 < BODY > 15 < FORM METHOD =POST ACTION ="" > 16ID < INPUT TYPE ="text" id ="txtInt" NAME ="txtInt" maxlength ="6" feildtype ="integer" msg =",<%=IMSG0002%>" >< br > 17ID < INPUT TYPE ="text" id ="txtInt" NAME ="txtInt" maxlength ="6" feildtype ="integer" msg =",<%=IMSG0002%>" >< br > 18ID < INPUT TYPE ="text" id ="txtInt" NAME ="txtInt" maxlength ="6" feildtype ="integer" msg =",<%=IMSG0002%>" >< br > 19ID < INPUT TYPE ="text" id ="txtInt" NAME ="txtInt" maxlength ="6" feildtype ="integer" msg =",<%=IMSG0002%>" >< br > 2021名称 < INPUT TYPE ="text" id ="txtString" NAME ="txtString" maxlength ="5" feildtype ="string" msg ="<%=IMSG0003%>,<%=IMSG0004%>" mustitem ="true" >< br > 22名称 < INPUT TYPE ="text" id ="txtString" NAME ="txtString" maxlength ="5" feildtype ="string" msg ="<%=IMSG0003%>,<%=IMSG0004%>" mustitem ="true" >< br > 23名称 < INPUT TYPE ="text" id ="txtString" NAME ="txtString" maxlength ="5" feildtype ="string" msg ="<%=IMSG0003%>,<%=IMSG0004%>" mustitem ="true" >< br > 2425名称2 < INPUT TYPE ="text" id ="txtStr" NAME ="txtStr" maxlength ="5" feildtype ="string" msg ="<%=IMSG0003%>,<%=IMSG0004%>" mustitem ="true" >< br > 26 < INPUT TYPE ="button" value ="submit" onclick ="validate(); return false;" > 27 < SCRIPT LANGUAGE ="JavaScript" > ... 28<!--29//validate()30//-->31 </ SCRIPT > 32 </ FORM > 33 </ BODY > 34 </ HTML > validate.js function validate() ... { 2 3 //var objs = document.all; 4 //var Elements = document.getElementsByTagName("*"); 5 var Elements; 6 var ctlArray; 7 var ctlArrayName; 8 var i, j; 9 var elLen, arrLen;10 var msgs;1112 Elements = document.getElementsByTagName("input");13 arrName ="";1415 for ( i in Elements ) ...{16 elLen = Elements[i].length;1718 if (elLen > 1) ...{19 ctlArray = Elements[i];20 arrLen = ctlArray.length;2122 if (arrName != ctlArray[0].name) ...{23 arrName = ctlArray[0].name;2425 for (j=0; j < arrLen; j++) ...{26 if (checkValue(ctlArray[j]) == false) ...{27 return false;28 } 29 }3031 }3233 }else...{3435 if (checkValue(Elements[i]) == false) ...{36 return false;37 }38 }39 }4041 return true;42} 43 44 function checkValue (obj) ... {4546 var len;47 len = obj.maxLength;4849 if ( obj.type == "text" ) ...{5051 //if (obj.msg != undefined ) {52 if ( obj.msg ) ...{53 msgs = obj.msg.split(",");54 } else ...{55 return true;56 }5758 if ( trim(obj.value) == "" && obj.mustitem && obj.mustitem == "true") ...{59 alert(msgs[0]);60 getFocusSelect(obj);61 return false;62 }else ...{6364 if ( trim(obj.value) != ""&& obj.feildtype && obj.feildtype == "integer" ) ...{6566 if ( checkNumLen(obj.value, len) == false ) ...{67 alert(msgs[1]);68 getFocusSelect(obj);69 return false;70 }7172 } else if ( trim(obj.value) != "" && obj.feildtype && obj.feildtype == "string" ) ...{7374 if ( getLenthByByte(trim(obj.value)) > len)...{75 alert(msgs[1]);76 getFocusSelect(obj);77 return false;78 }79 }80 }81 }8283} message.inc <% 2Const IMSG0001 = " ID必须输入! " 3Const IMSG0002 = " ID输入格式错误! " 4Const IMSG0003 = " 名称必须输入! " 5Const IMSG0004 = " 名称输入格式错误! " 6 %>