解决方案 »

  1.   

    你写的有问题,你的验证是新密码和旧密码必须一致。equalTo : "#oldPass" 你这是要新密码和旧密码一致。
      

  2.   

    示例,对比一下,或者加下面放在你的页面看是否正常,是否受到其他因素的影响<!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>jQuery validation plug-in - main demo</title><link rel="stylesheet" href="css/screen.css" /><script src="http://jquery.bassistance.de/validate/lib/jquery.js"></script>
    <script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script><script>
    $.validator.setDefaults({
    submitHandler: function() { alert("submitted!"); }
    });$().ready(function() {
    // validate the comment form when it is submitted
    $("#commentForm").validate(); // validate signup form on keyup and submit
    $("#signupForm").validate({
    onfocusout: function(element) { $(element).valid(); }, 
    rules: {
    firstname: "required",
    lastname: "required",
    username: {
    required: true,
    minlength: 2
    },
    password: {
    required: true,
    minlength: 5
    },
    confirm_password: {
    required: true,
    minlength: 5,
    equalTo: "#password"
    },
    email: {
    required: true,
    email: true
    },
    topic: {
    required: "#newsletter:checked",
    minlength: 2
    },
    agree: "required"
    },
    messages: {
    firstname: "Please enter your firstname",
    lastname: "Please enter your lastname",
    username: {
    required: "Please enter a username",
    minlength: "Your username must consist of at least 2 characters"
    },
    password: {
    required: "Please provide a password",
    minlength: "Your password must be at least 5 characters long"
    },
    confirm_password: {
    required: "Please provide a password",
    minlength: "Your password must be at least 5 characters long",
    equalTo: "Please enter the same password as above"
    },
    email: "Please enter a valid email address",
    agree: "Please accept our policy"
    }
    }); // propose username by combining first- and lastname
    $("#username").focus(function() {
    var firstname = $("#firstname").val();
    var lastname = $("#lastname").val();
    if(firstname && lastname && !this.value) {
    this.value = firstname + "." + lastname;
    }
    }); //code to hide topic selection, disable for demo
    var newsletter = $("#newsletter");
    // newsletter topics are optional, hide at first
    var inital = newsletter.is(":checked");
    var topics = $("#newsletter_topics")[inital ? "removeClass" : "addClass"]("gray");
    var topicInputs = topics.find("input").attr("disabled", !inital);
    // show when newsletter is checked
    newsletter.click(function() {
    topics[this.checked ? "removeClass" : "addClass"]("gray");
    topicInputs.attr("disabled", !this.checked);
    });
    });
    </script><style type="text/css">
    #commentForm { width: 500px; }
    #commentForm label { width: 250px; }
    #commentForm label.error, #commentForm input.submit { margin-left: 253px; }
    #signupForm { width: 670px; }
    #signupForm label.error {
    margin-left: 10px;
    width: auto;
    display: inline;
    }
    #newsletter_topics label.error {
    display: none;
    margin-left: 103px;
    }
    </style></head>
    <body><h1 id="banner"><a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">jQuery Validation Plugin</a> Demo</h1>
    <div id="main"><p>Default submitHandler is set to display an alert into of submitting the form</p><form class="cmxform" id="commentForm" method="get" action="">
    <fieldset>
    <legend>Please provide your name, email address (won't be published) and a comment</legend>
    <p>
    <label for="cname">Name (required, at least 2 characters)</label>
    <input id="cname" name="name" minlength="2" type="text" required />
    <p>
    <label for="cemail">E-Mail (required)</label>
    <input id="cemail" type="email" name="email" required />
    </p>
    <p>
    <label for="curl">URL (optional)</label>
    <input id="curl" type="url" name="url" />
    </p>
    <p>
    <label for="ccomment">Your comment (required)</label>
    <textarea id="ccomment" name="comment" required></textarea>
    </p>
    <p>
    <input class="submit" type="submit" value="Submit"/>
    </p>
    </fieldset>
    </form><form class="cmxform" id="signupForm" method="get" action="">
    <fieldset>
    <legend>Validating a complete form</legend>
    <p>
    <label for="firstname">Firstname</label>
    <input id="firstname" name="firstname" type="text" />
    </p>
    <p>
    <label for="lastname">Lastname</label>
    <input id="lastname" name="lastname" type="text" />
    </p>
    <p>
    <label for="username">Username</label>
    <input id="username" name="username" type="text" />
    </p>
    <p>
    <label for="password">Password</label>
    <input id="password" name="password" type="password" />
    </p>
    <p>
    <label for="confirm_password">Confirm password</label>
    <input id="confirm_password" name="confirm_password" type="password" />
    </p>
    <p>
    <label for="email">Email</label>
    <input id="email" name="email" type="email" />
    </p>
    <p>
    <label for="agree">Please agree to our policy</label>
    <input type="checkbox" class="checkbox" id="agree" name="agree" />
    </p>
    <p>
    <label for="newsletter">I'd like to receive the newsletter</label>
    <input type="checkbox" class="checkbox" id="newsletter" name="newsletter" />
    </p>
    <fieldset id="newsletter_topics">
    <legend>Topics (select at least two) - note: would be hidden when newsletter isn't selected, but is visible here for the demo</legend>
    <label for="topic_etflash">
    <input type="checkbox" id="topic_etflash" value="etflash" name="topic" />
    Marketflash
    </label>
    <label for="topic_fuzz">
    <input type="checkbox" id="topic_fuzz" value="fuzz" name="topic" />
    Latest fuzz
    </label>
    <label for="topic_digester">
    <input type="checkbox" id="topic_digester" value="digester" name="topic" />
    Mailing list digester
    </label>
    <label for="topic" class="error">Please select at least two topics you'd like to receive.</label>
    </fieldset>
    <p>
    <input class="submit" type="submit" value="Submit"/>
    </p>
    </fieldset>
    </form><h3>Synthetic examples</h3>
    <ul>
    <li><a href="errorcontainer-demo.html">Error message containers in action</a></li>
    <li><a href="custom-messages-data-demo.html">Custom Messages as Element Data</a></li>
    <li><a href="radio-checkbox-select-demo.html">Radio and checkbox buttons and selects</a></li>
    <li><a href="ajaxSubmit-integration-demo.html">Integration with Form Plugin (AJAX submit)</a></li>
    <li><a href="custom-methods-demo.html">Custom methods and message display.</a></li>
    <li><a href="dynamic-totals.html">Dynamic forms</a></li>
    <li><a href="themerollered.html">Forms styled with jQuery UI Themeroller</a></li>
    <li><a href="tinymce/">TinyMCE Demo</a></li>
    <li><a href="file_input.html">File inputs</a></li>
    <li><a href="jquerymobile.html">jQuery Mobile Form Validation</a></li>
    </ul>
    <h3>Real-world examples</h3>
    <ul>
    <li><a href="milk/">Remember The Milk signup form</a></li>
    <li><a href="eto/">Marketo signup form</a></li>
    <li><a href="multipart/">Buy and Sell a House multipart form</a></li>
    <li><a href="captcha/">Remote captcha validation</a></li>
    </ul><h3>Testsuite</h3>
    <ul>
    <li><a href="../test/">Validation Testsuite</a></li>
    </ul></div>
    </body>
    </html>
      

  3.   

    newPass : {
    required : true,
    minlength : 6,
    maxlength : 20,
    equalTo : "#renewPass "
    },
    renewPass : {
    required : true,
    equalTo : "#newPass"
    }我没用过这个验证, 按照你这个东西, newPass  -> equalTo : "#renewPass ";   renewPass ->equalTo : "#newPass"这样才是两个一致吧,你是这么改的吗
      

  4.   


    我看网上写的介绍,只需要其中一个写equalTo 就可以了,不需要两个都写
      

  5.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>第一个简单的jQuery程序</title><link type="text/css" rel="stylesheet" href="../css/jquery-validation/css/screen.css" /><link type="text/css" rel="stylesheet" href="../css/index.css" />    <script language="javascript" type="text/javascript" 
                src="../js/jquery-1.4.1.js"></script>
    <script language="javascript" type="text/javascript" 
                src="../js/jquery-validation/jquery.validate.min.js"></script>
    <script type="text/javascript"
    src="../js/jquery-validation/additional-methods.min.js"></script>

        <script type="text/javascript">
      jQuery.validator.addMethod("check", function(value, element) {
       
    return $("#omima").val()!=$("#nmima").val();
         }, "新旧密码不能一样!");jQuery.extend(jQuery.validator.messages, {
        required: "必选字段",
        remote: "请修正该字段",
        email: "请输入正确格式的电子邮件",
        url: "请输入合法的网址",
        date: "请输入合法的日期",
        dateISO: "请输入合法的日期 (ISO).",
        number: "请输入合法的数字",
        digits: "只能输入整数",
        creditcard: "请输入合法的信用卡号",
        equalTo: "请输入相同的值  ",
        accept: "请输入拥有合法后缀名的字符串",
        maxlength: jQuery.format("请输入一个长度最多是 {0} 的字符串"),
        minlength: jQuery.format("请输入一个长度最少是 {0} 的字符串"),
        rangelength: jQuery.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
        range: jQuery.format("请输入一个介于 {0} 和 {1} 之间的值"),
        max: jQuery.format("请输入一个最大为 {0} 的值"),
        min: jQuery.format("请输入一个最小为 {0} 的值")
    });
        $(function(){
        var vali = {
            rules: {
                omima: {
                    required: true
                },
                nmima: {
                    required: true,maxlength:20,minlength:6,check:true
                },
     rmima: {
                    equalTo:"#nmima"
                }
            }
        };
        $("#loginForm").validate(vali);
    });
              
        </script>
    </head>
    <body><form id="loginForm" action="#" method="post">
    <table border="1">
    <tr><td style="text-align:right">旧密码:</td><td><input type="password" id="omima" name="omima" style="width:120px;height:20px "></td></tr>
    <tr><td style="text-align:right">新密码:</td><td><input type="password" id="nmima" name="nmima" style="width:120px;height:20px "></td></tr>
    <tr><td style="text-align:right">确认密码:</td><td><input type="password" id="rmima" name="rmima" style="width:120px;height:20px "></td></tr>
    <tr><td colspan="2" style="text-align:center; padding-top:15px"><input type="submit" value="提交"></td></tr>
    </table>
    </form></body>
    </html>

    我测试了可以用
      

  6.   

    你的文本框没有设置ID,equalTo: 后面是#开始的是根据ID取值比较的。取不到值所以一值不等。
      

  7.   


    不是根据name属性吗。。#开始是根据ID选取的 ,这就是一个选择器,你可以加个ID和name一样试试。 
      

  8.   


    不是根据name属性吗。。#开始是根据ID选取的 ,这就是一个选择器,你可以加个ID和name一样试试。 
    确实是这个问题,我要记录下,谢谢,纠结了我半天