如何使用按钮禁用或启用以下验证? pageload
加载以下函数,我不知道如何卸载它。
$(document).ready(function() {
//* regular validation
gebo_validation.reg();
});
//* validation
gebo_validation = {
reg: function() {
reg_validator = $('.form_validation_reg').validate({
onkeyup: false,
errorClass: 'error',
validClass: 'valid',
highlight: function(element) {
$(element).closest('div').addClass("f_error");
},
unhighlight: function(element) {
$(element).closest('div').removeClass("f_error");
},
errorPlacement: function(error, element) {
$(element).closest('div').append(error);
},
rules: {
campaign_name: {
require_from_group: [1, '.span8'],
minlength: 3,
//notBoth: ['input[name="exist_campaign_name"]']
},
exist_campaign_name: {
require_from_group: [1, '.span8'],
minlength: 3,
//notBoth: ['input[name="campaign_name"]']
},
},
invalidHandler: function(form, validator) {
$.sticky("There are some errors. Please correct them and submit again.", {autoclose : 5000, position: "top-right", type: "st-error" });
}
});
$('.span8').on('blur', function () {
if ($(this).val() != '') {
$('.span8').not(this).prop('disabled', 'disabled');
} else {
$('.span8').not(this).removeProp('disabled');
}
});
//Some extra validation methods.
/* jQuery.validator.addMethod('notBoth', function (value, element, param) {
return ((value != '') && ($(param[0]).val() == '') || (value == '') && ($(param[0]).val() != ''));
}, "Please do not fill out both fields"); */
}
};
答案 0 :(得分:0)
我在这里找到了解决方案.. jQuery validate - set conditional rules based on user selection
使用示例代码:
$('#myform').validate({
rules: {
fieldA: {
required:'#checkA:checked'
}
}
});