JQuery.validate 错误信息对话框

 1 <script
 2     src="${pageContext.request.contextPath}/static/js/jquery-1.12.1.js"type="text/javascript">
 3 </script>
 4 <script
 5     src="${pageContext.request.contextPath}/static/js/jquery.validate.js"type="text/javascript">
 6 </script>
 7 <script type="text/javascript">
 8 $(function(){
 9 
10     $(".123").validate({
11         rules:{
12             name:{
13                 required:true
14             },
15             mima:{
16                 required:true
17             }
18         },
19         messages:{
20             name:{
21                 required:"用户名不能为空"
22             },
23             mima:{
24                 required:"密码不能为空"
25             }
26         },
27         errorPlacement: function (error, element) {
28                alert(error.html()); 
29         }      
31     })
32 })
33 </script>
34 <body>
35     <form action="" method="post" class="123">
36         用户名<input id="name" name="name">
37         密码<input id="mima" name="mima">
38         <input type="submit" value="提交">
39     </form>
40 </body>

运行结果

          

原文地址:https://www.cnblogs.com/Zhanghaonihao/p/7652713.html