zoukankan      html  css  js  c++  java
  • jquery.validate的 使用

     需要引入jar包

    <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.validate/jquery.validate.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.validate/additional-methods.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.validate/localization/messages_zh.js"></script>
    <form id="savePassWord"  method="post">

    校验的方法为:

    function checkInputPass(){
           $("#savePassWord").validate({ //验证的按钮触发
               rules: {
                   "oldpassword": { //name
                       required: true,
                       minlength: 3
                   },
                   "password": {
                       required: true,
                       minlength: 3
                   },
                   "surepassword": {
                       required: true,
                        equalTo: "#passwordId"  //id
                   }
               },
               messages: {
                   "oldpassword": {
                       required: '原密码不能为空!',
                      minlength: $.validator.format('原密码不能小于{0}!')
                   },
                   "password": {
                       required: '新密码不能为空!',
                      minlength: $.validator.format('新密码不能小于{0}!')
                   },
                   "surepassword": {
                       required: '确认新密码不能为空!',
                        equalTo: '请输入与上面相同的密码!'
                   }
               },
               // 错误的位置设置
               errorPlacement: function(error, element)
               { 
                   error.appendTo($(element).parent().find("span"));
               },
               // 提交拦截处理,specifying a submitHandler prevents the default submit, good for the demo
               submitHandler: function(form)
               {
               
               }
           });
    }
  • 相关阅读:
    j2EE(转)
    java_jdbc
    Java_pom(转)
    Java 特性
    mybatis-plus一些通用方法
    synchronized和lock的区别和使用
    JQGrid之文件上传
    项目调试Bug集锦(更新中)
    SpringMVC的流程
    Java小白进阶之值传递-引用传递
  • 原文地址:https://www.cnblogs.com/ld-swust/p/5201323.html
Copyright © 2011-2022 走看看