当前位置:   article > 正文

HTML多选验证js函数,javascript实现的自动验证函数_javascript教程

javascript 的checkvalue()函数

test.htm

1

2

3

4

New Document

5   

6   

7   

8   

9

10

11

12

13

14

15

16ID” >

17ID” >

18ID” >

19ID” >

20

21名称,” mustitem=”true”>

22名称,” mustitem=”true”>

23名称,” mustitem=”true”>

24

25名称2,” mustitem=”true”>

26

27

28

29//validate()

30//–>

31

32

33

34

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;

24

25                for (j=0; j < arrLen; j++) {

26                    if (checkValue(ctlArray[j]) == false) {

27                        return false;

28                    }

29                }

30

31            }

32

33        }else{

34

35            if (checkValue(Elements[i]) == false) {

36                return false;

37            }

38        }

39    }

40

41    return true;

42}

43

44function checkValue (obj){

45

46    var len;

47    len = obj.maxLength;

48

49    if ( obj.type == “text” ) {

50

51        //if (obj.msg != undefined ) {

52        if ( obj.msg ) {

53            msgs = obj.msg.split(“,”);

54        } else {

55            return true;

56        }

57

58        if ( trim(obj.value) == “” && obj.mustitem && obj.mustitem == “true”) {

59            alert(msgs[0]);

60            getFocusSelect(obj);

61            return false;

62        }else {

63

64            if ( trim(obj.value) != “”&& obj.feildtype && obj.feildtype == “integer” ) {

65

66                if ( checkNumLen(obj.value, len) == false ) {

67                    alert(msgs[1]);

68                    getFocusSelect(obj);

69                    return false;

70                }

71

72            } else if ( trim(obj.value) != “” && obj.feildtype && obj.feildtype == “string” ) {

73

74                if ( getLenthByByte(trim(obj.value)) > len){

75                    alert(msgs[1]);

76                    getFocusSelect(obj);

77                    return false;

78                }

79            }

80        }

81    }

82

83}

message.inc 1

2Const IMSG0001 = “ID必须输入!”

3Const IMSG0002 = “ID输入格式错误!”

4Const IMSG0003 = “名称必须输入!”

5Const IMSG0004 = “名称输入格式错误!”

6%>

http://www.cnblogs.com/meil/archive/2007/04/05/700772.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/110856
推荐阅读
相关标签
  

闽ICP备14008679号