jquery validate 插件实例教程

jquery validate是一个表单较难的jquery插件,在github上的地址是:https://github.com/jzaefferer/jquery-validation,应用比较简单,当然也可以从jquery的官网获取得到http://archive.plugins.jquery.com/project/validate。


使用的时候引用jquery的库和validate的库就可以了,使用方面看下面的例子。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
< html  xmlns = "http://www.w3.org/1999/xhtml"  lang = "en" >
< head >
     < meta  http-equiv = "Content-Type"  content = "text/html; charset=utf-8"  />
     < title >jquery validate 插件实例01</ title >
     < meta  name = "author"  content = "Administrator"  />
     < link  rel = "stylesheet"  type = "text/css"  href = "js/css/screen.css"  />
     < script  type = "text/javascript"  src = "js/jquery-1.9.0.js" ></ script >
     < script  type = "text/javascript"  src = "js/jquery.validate.js" ></ script >
     < script  type = "text/javascript" >
     $(function(){
             $("#myform").validate({
             rules:{
         username:"required",
         address:{
                 required:true,
             minlength:3
         },
         age:"digits",
         pwd:"required",
         cpwd:{
             equalTo:"#pwd"
         }
         },
         messages:{
         username:"用户名必须输入",
         address:{
                 required:"用户地址必须输入",
             minlength:"地址不能小于3位"
         },
         age:"年龄必须是整数",
         pwd:"密码必须输入",
         cpwd:"两次密码不一致"
         }
     });
     });
     </ script >
</ head >
< body >
     < form  id = "myform"  action = "#" >
     Username:< input  type = "text"  id = "username"  name = "username" />< br />
     Address:< input  type = "text"  id = "address"  name = "address" />< br />
     Age:< input  type = "text"  id = "age"  name = "age" />< br />
     password:< input  type = "text"  id = "pwd"  name = "pwd" />< br />
     confirm password:< input  type = "text"  id = "cpwd"  name = "cpwd" />< br />
     < input  type = "submit"  />
     </ form >
</ body >
</ html >


本文链接:jquery validate 插件实例教程,由领悟书生原创

转载请注明出处【http://www.656463.com/article/358】

你可能感兴趣的:(jquery validate 插件实例教程)