数据加载中……
jquery validation
 1<%@page contentType="text/html; charset=GBK"%>
 2<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 3<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
 4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 5<html xmlns="http://www.w3.org/1999/xhtml" lang="GBK" xml:lang="GBK">
 6<head>
 7<meta http-equiv="Pragma" content="no-cache" />
 8<meta http-equiv="Cache-Control" content="no-cache" />
 9<meta http-equiv="Expires" content="0" />
10<link type="text/css" title="www" rel="stylesheet" media="all" href="<c:url value="/theme/1/control/control.css"/>" />
11<title>jQuery之验证插件</title>
12    <style type='text/css'>
13           *{font-family:Verdana;font-size:96%;}
14           label.error{float:none;color:red;padding-left:.5em;vertical-align:top;}
15           p{clear:both;}
16           .submit{margin-left:12em;}
17           em{font-weight:bold;vertical-align:top;}
18       
</style>
19<script type='text/javascript'  src='<c:url value="/js/jquery-1.3.2.js"/>'></script>
20<script type='text/javascript' src='<c:url value="/js/jquery.validate.js"/>'></script>
21<script type='text/javascript'>
22           $(document).ready(function(){
23              $('#commentForm').validate({
24                  rules:{
25                     username:{
26                         required:true,
27                         minlength:1,
28                         formula:"7+9"
29                     }
,
30                     email:{
31                         required:true,
32                         email:true
33                     }
,
34                     url:"url",
35                     comment:"required",
36                     coco:{formula:"7+9"},
37                     valcode:{formula:"7+9"}
38                  }
,
39                  messages: {   
40                         //为name为email的控件的required()和email()验证方法设置验证失败的消息内容   
41                         email: {required:"需要输入电子邮箱", email:"电子邮箱格式不正确"}   
42                     }
  
43              }
)
44           }
);
45
46           $.validator.addMethod(   
47                    "formula",                       //验证方法的名称   
48                    function(value,element,param){   //验证规则   
49                       return value==eval(param);    
50                       }
,   
51                      '请输入正确的结果'                //提示验证信息   
52            );   
53       
</script>
54</head>
55
56<body>
57       <form class='cmxform' id='commentForm' method='post' action='#'>
58           <fieldset>
59              <legend>一个简单的带有提示的评论例子</legend>
60              <p>
61                  <label for='cusername'>姓名</label><em>*</em>
62                  <input id='cusername' name='username' size='25' />
63              </p>
64              <p>
65                  <label for='cemail'>电子邮件</label><em>*</em>
66                  <input id='cemail' name='email' size='25' />
67              </p>
68              <p>
69                  <label for='curl'>网址</label><em>*</em>
70                  <input id='curl' name='url' size='25' value=''/>
71              </p>
72              <p>
73                  <label for='cverify'>7+9=</label><em>*</em>
74                  <input id='cverify' name='coco' size='25' value=''/>
75              </p>
76<p>  
77    <label for='cvalcode'>验证码</label>  
78    <input id='cvalcode' name='valcode' size='25' value=''/>=7+9   
79</p> 
80              <p>
81                  <label for='ccomment'>你的评论</label><em>*</em>
82                  <textarea id='ccomment' name='comment' cols='25'></textarea>
83              </p>
84              <p>
85                  <input class='submit' type='submit' value='提交'>
86              </p>
87           </fieldset>
88       </form>
89    </body>
90</html>
91
92
93
94

posted on 2009-10-15 13:37 R99 阅读(385) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: