我将使用" jquery表单验证插件"来构建控件。我想" init"部分点击功能将被删除,当我将成为激活新功能。或者我想听听您针对这种情况的替代解决方案。
你能帮助我吗?感谢。var FormValidation = function() {
var Profile = function() {
var error2 = $('div#tab_1_1 .alert-danger', $('#form1'));
var success2 = $('div#tab_1_1 .alert-success', $('#form1'));
$('#form1').validate({
errorElement: 'span',
errorClass: 'help-block help-block-error',
focusInvalid: true,
ignore: "",
rules: {
name: {
minlength: 2,
required: true
},
lastname: {
minlength: 2,
required: true
}
}
});
}
var ProfileTwo = function() {
var error2 = $('div#tab_1_2 .alert-danger', $('#form1'));
var success2 = $('div#tab_1_2 .alert-success', $('#form1'));
$('#form1').validate({
errorElement: 'span',
errorClass: 'help-block help-block-error',
focusInvalid: true,
ignore: "",
rules: {
name: {
minlength: 2,
required: true
},
lastname: {
minlength: 2,
required: true
}
}
});
}
var Func = Profile();
return {
init: function() {
$("ul#ProfileTabs li").click(function() {
Func = null;
var DataID = $(this).find("a").data("id");
if (DataID === "tab_1_1") {
Func = Profile();
} else if (DataID === "tab_1_2") {
Func = ProfileTwo();
} else {
Func = null;
}
Func();
});
}
};
}();
jQuery(document).ready(function() {
FormValidation.init();
});
答案 0 :(得分:0)
我会让Profile1和Profile2函数只返回验证对象。
On tab click
然后我会先打电话给unbind
$('#form1').data('validator', null);
$("#form1").unbind('validate');
然后重新附加新的个人资料
validate_obj = <get PROFILE1 or PROFILE2>
$('#form1').validate( validate_obj );