Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery验证等式无法使用引导_Jquery_Bootstrap 4_Jquery Validate - Fatal编程技术网

Jquery验证等式无法使用引导

Jquery验证等式无法使用引导,jquery,bootstrap-4,jquery-validate,Jquery,Bootstrap 4,Jquery Validate,我有一个带有密码字段的表单,我想通过比较两个密码字段的值来验证该表单: <div class="form-group"> <label for="pwd">Password:</label> <input type="password" class="form-control" id="pwd" name="pwd" required&

我有一个带有密码字段的表单,我想通过比较两个密码字段的值来验证该表单:

<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" name="pwd" required>
</div>
<div class="form-group">
<label for="repwd">Retype Password:</label>
<input type="password" class="form-control" id="repwd" name="repwd" required>
</div>

所需规则已验证,但equalTo未验证。如何解决这个问题?

您可以简单地将
equalTo
添加到
pwd
中,因为这里
repwd
应该等于
pwd
,而不是像您在jquery代码更改中所做的那样,它应该工作

演示代码

$(“#注册表执行”)。验证({
规则:{
pwd:“必需的”,//必需的pwd
报告:{
必需:true,//需要repwd
相等:“#pwd”//应等于pwd
}
},
onkeyup:函数(元素){
这个,元素(元素),;
},
submitHandler:函数(表单){
//为有效的表格做其他事情
表单提交();
},
});
$('#pwd')。在('change blur keyup',function()上{
$('#pwd').valid();
});

密码:
重新键入密码:
$("#registerform").validate({
    rules: {
        pwd: {
            required: true,
            equalTo: "#repwd"
        },
        repwd: {
            required: true,
            equalTo: "#pwd"
        }
    },
    messages: {
        repwd: {
            equalTo: "Should be equal"
        }
    },
    onkeyup: function(element){
        this.element(element);
    },
    submitHandler: function(form) {
    // do other things for a valid form
     form.submit();
    },
});

 $('#pwd').on('change blur keyup', function() {
    $('#pwd').valid();
});