jQuery之Validation表单验证插件使用

2021-05-17 10:27

阅读:305

YPE html>

标签:closed   分享   username   电子邮件   nbsp   http   element   fun   3.2   















姓名:



电子邮件:



网址:



我的评论:



=7+9






代码详情如下:

技术分享技术分享
 1 DOCTYPE html>
 2 html xmlns="http://www.w3.org/1999/xhtml">
 3 head>
 4     meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5     title>title>
 6     script src="jquery-3.2.1.js">script>
 7     script src="jquery-validation-1.17.0/dist/jquery.validate.js">script>
 8     script src="jquery.metadata.js">script>
 9     script src="jquery-validation-1.17.0/dist/localization/messages_zh.js">script>
10     script>
11         $(function () {
12             //$("#addForm").validate({
13             //    rules: {
14             //        username: {
15             //            required: true,
16             //            minlength: 4
17             //        },
18             //        email: {
19             //            required: true,
20             //            email: true
21             //        },
22             //        address: "url",
23             //        content: "required"
24             //    }
25             //});
26             $("#addForm").validate({
27                 rules: {
28                     username: { required: true, minlength: 2 },
29                     email: { required: true, email: true },
30                     address: "url",
31                     content: "required",
32                     cvalcode: { formual: "7+9" }
33                 }
34             });
35         });
36         $.validator.addMethod(
37                 "formual",
38                 function (value, element, param) {
39                     return value == eval(param);
40                 },
41                 请输入正确的结果
42             );
43     script>
44 head>
45 body>
46     form action="#" method="post" id="addForm">
47         p>
48             姓名:
49             input type="text" name="username" value=" " />
50         p>
51         p>
52             电子邮件:
53             input type="text" name="email" value=" " />
54         p>
55         p>
56             网址:
57             input type="text" name="address" value=" " />
58         p>
59         p>
60             我的评论:
61             textarea name="content">textarea>
62         p>
63         label for="cvalcode">验证码label>
64         input type="text" name="cvalcode" id="cvalcode" value=" " />=7+9
65         p>
66             input type="submit" name="tijiao" value="提交" />
67         p>
68     form>
69 body>
70 html>
View Code

 

jQuery之Validation表单验证插件使用

标签:closed   分享   username   电子邮件   nbsp   http   element   fun   3.2   

原文地址:http://www.cnblogs.com/pang951189/p/7744979.html


评论


亲,登录后才可以留言!