使用 jquery 规则确认密码无效

Confirm password using jquery rules not working

我需要在 cpassword 中获取相同的密码。但是这里虽然密码匹配,但会给出密码不匹配的错误。当我删除 equalTo 规则时,这些方法工作正常。

所以我认为问题出在 ,cpassword'

rules: {
    password: {
      required: true,
      minlength: 8,
      remote: {
        url: baseURL + "member/checkPassword1",
        type: "post",
        data: {
          action: function() {
            return "checkPassword1";
          }
        }
      }
    },
    cpassword: {
      required: true,
      equalTo: "#password"
    }
  },
  messages: {
    password: {
      required: "Please enter the password!",
      minlength: "Password should contain at least 8 character!"
    },
    cpassword: {
      required: "Please confirm the password!",
      equalTo: "Confirm password doesn't match the Password"
    }
  },

查看

<div class="form-group">
    <label class="headlabel"><?=$this->lang->line("Password");?><strong>*</strong></label>
    <input class="formtext form-control" type="password" name="password" id="password" value="<?php echo set_value('password'); ?>" onkeypress="removeerror('password')" placeholder=" <?=$this->lang->line("Enter_your_passwrd");?> ">
    <span class="glyphicon glyphicon-remove right errorcross" id="password_cross" style=""></span>
    <label class="errorlabel" id="password_error"><?php echo form_error('password'); ?></label>
</div>
<div class="form-group">
    <label class="headlabel"><?=$this->lang->line("Confirm_password");?><strong>*</strong></label>
    <input class="formtext form-control" type="password" name="cpassword" id="cpassword1" value="<?php echo set_value('cpassword'); ?>" onkeypress="removeerror('cpassword')" placeholder=" <?=$this->lang->line("Retype_your_passsword");?> ">
    <span class="glyphicon glyphicon-remove right errorcross" id="cpassword_cross" style=""></span>
    <label class="errorlabel" id="cpassword_error"><?php echo form_error('cpassword'); ?></label>
</div>

有人对此有任何想法吗?我该如何更正它?

在您的 HTML for cpassword 输入元素中添加 data-rule-equalto='#password' 属性 并进行检查