下面,图老师小编带您去了解一下Javascript实现的自动验证函数,生活就是不断的发现新事物,get新技能~
【 tulaoshi.com - Web开发 】
test.htm
1!-- #include file="message.inc" --
2HTML
3HEAD
4TITLE 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"
9script src="common.js"/script
10script src="validate.js"/script
11
12/HEAD
13
14BODY
15FORM METHOD=POST ACTION=""
16IDINPUT TYPE="text" id="txtInt" NAME="txtInt" maxlength="6" feildtype="integer" msg=",%=IMSG0002%" br
17IDINPUT TYPE="text" id="txtInt" NAME="txtInt" maxlength="6" feildtype="integer" msg=",%=IMSG0002%" br
18IDINPUT TYPE="text" id="txtInt" NAME="txtInt" maxlength="6" feildtype="integer" msg=",%=IMSG0002%" br
19IDINPUT TYPE="text" id="txtInt" NAME="txtInt" maxlength="6" feildtype="integer" msg=",%=IMSG0002%" br
20
21名称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
24
25名称2INPUT TYPE="text" id="txtStr" NAME="txtStr" maxlength="5" feildtype="string" msg="%=IMSG0003%,%=IMSG0004%" mustitem="true"br
26INPUT TYPE="button" value="submit" onclick="validate(); return false;"
27SCRIPT LANGUAGE="JavaScript"
28!--
29//validate()
30//--
31/SCRIPT
32/FORM
33/BODY
34/HTML
35
validate.js
1function 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;
11
12 Elements = document.getElementsByTagName("input");
13 arrName ="";
14
15 for ( i in Elements ) {
16 elLen = Elements[i].length;
17
18 if (elLen 1) {
19 ctlArray = Elements[i];
20 arrLen = ctlArray.length;
21
22 if (arrName != ctlArray[0].name) {
23 arrName = ctlArray[0].name;
message.inc 1%
2Const IMSG0001 = "ID必须输入!"
3Const IMSG0002 = "ID输入格式错误!"
4Const IMSG0003 = "名称必须输入!"
5Const IMSG0004 = "名称输入格式错误!"
6%
来源:http://www.tulaoshi.com/n/20160219/1610157.html
看过《Javascript实现的自动验证函数》的人还看了以下文章 更多>>