Jquery验证EqualTo问题

时间:2014-12-11 05:54:55

标签: jquery-validate asp.net-mvc-5

我有以下代码

  $("#emailForm").validate({
    rules: {
        "UserPasswordReset.EmailAddress": {
            maxlength: 256,
            email: true,
        },
        "UserPasswordReset.ConfirmEmailAddress": {
            maxlength: 256,
            email: true,
            equalTo: "#UserPasswordReset.EmailAddress"
        }
    }
});

当我填写下面的表格并按提交我在确认框中说,请输入相同的值,所以我检查,仔细检查,并为了上帝的爱我再次检查,但我仍然得到请输入相同的值甚至虽然两个领域都是相同的。

<div id="home" class="tab-pane active" role="tabpanel">
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="form-field-1-1"> Email</label>
    <div class="col-sm-9">
        <input id="emailaddress" class="col-xs-10 col-sm-5" type="text" value="" name="UserPasswordReset.EmailAddress" data-val-required="The EmailAddress field is required." data-val="true" autocomplete="off" placeholder="Please enter your email address">
    </div>
</div>
<div class="form-group">
    <label class="col-sm-1 control-label no-padding-right" for="form-field-1-1"> Confirm </label>
    <div class="col-sm-9">
        <input id="confirm_email" class="col-xs-10 col-sm-5" type="text" value="" name="UserPasswordReset.ConfirmEmailAddress" autocomplete="off" placeholder="Please confirm your email address">
    </div>
</div>
<button id="btnSaveEmail" class="btn btn-info pull-right" type="Submit" value="true" name="SaveEmailAddress"> Update Email </button>
</div>

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

ConfirmEmailAddress规则

equalTo: "#UserPasswordReset.EmailAddress"

您没有id="UserPasswordReset.EmailAddress"的控件(只有一个id="emailaddress")。将其更改为

equalTo: "#emailaddress"