我想在验证为false时启用按钮,实际上我是这个jquery验证器插件的新手,这是我正在使用的代码
(input)
答案 0 :(得分:0)
以下是解决方案:https://codepen.io/creativedev/pen/NzgPBK
$("#per-btn").on('click', function(event) {
event.preventDefault();
$(this).addClass("disabled");
//var fileInput = document.getElementById('file');
//var file = fileInput.files[0];
$("#dataForm").validate({
rules: {
accountNameInput: {
required: true,
minlength: 10,
number: true,
maxlength: 10
},
// file: "required",
},
messages: {
val_phone: "Enter valid Phone no",
// file: "Upload an image",
},
submitHandler: function(form) {
alert('hai');
}
});
$('#dataForm').on('blur keyup change', 'input', function(event) {
validateForm('#dataForm');
});
function validateForm(id) {
var valid = $(id).validate().checkForm();
console.log(valid)
if (valid) {
$("#per-btn").prop('disabled', false);
$("#per-btn").removeClass('disabled');
} else {
$("#per-btn").addClass('disabled');
}
}
validateForm('#dataForm');
})