我正在使用 jquery.validate 在提交到服务器之前验证客户端的一些输入字段。效果很好!这组特定的字段出现在一个模式中,页面上还有两个其他模式在不同时间弹出,具体取决于用户点击的内容;但是,我的验证仅在其中一个模式上进行,即使该模式不在屏幕上,它也会阻止我的服务器端提交。
下面是我在 .js 中用于模态处理的代码,我要抑制的是“modalChgPass”。
(function (window) {
var
$ = window.jQuery,
modalEdit = '#modal-preferences-edit',
modalPreferencesEditOpts = {
autoOpen: true,
modal: true,
resizable: false,
draggable: false,
width: '700',
height: '670',
dialogClass: 'modal',
appendTo: 'form',
close: function () { $(this).dialog('destroy'); }
};
modalChgPass = '#modal-password-change',
modalPasswordChangeOpts = {
autoOpen: true,
modal: true,
resizable: false,
draggable: false,
width: '450',
height: '550',
dialogClass: 'modal',
appendTo: 'form',
close: function () { $(this).dialog('destroy'); }
};
modalActive = '#modal-card-activate',
modalCardActivateOpts = {
autoOpen: true,
modal: true,
resizable: false,
draggable: false,
width: '700',
height: '265',
dialogClass: 'modal',
appendTo: 'form',
close: function() { $(this).dialog('destroy'); }
};
$(document).ready(function () {
$('#btn-modal-password-change').click(function () {
$(modalChgPass).dialog(modalPasswordChangeOpts);
$(modalChgPass).dialog('open');
$('.ui-widget-overlay').click(function () {
$('.ui-dialog-content').dialog('close');
});
return false;
});
$('#chg-Password-btn').click(function () {
$(modalChgPass).dialog(modalPasswordChangeOpts);
$(modalChgPass).dialog('open');
$('.ui-widget-overlay').click(function () {
$('.ui-dialog-content').dialog('close');
});
return false;
});
$('#btn-modal-card-activate').click(function () {
$(modalActive).dialog(modalCardActivateOpts);
$(modalActive).dialog('open');
$('.ui-widget-overlay').click(function () {
$('.ui-dialog-content').dialog('close');
});
return false;
});
$('#btn-modal-preferences-edit').click(function () {
$(modalEdit).dialog(modalPreferencesEditOpts);
$(modalEdit).dialog('open');
$('.ui-widget-overlay').click(function () {
$('.ui-dialog-content').dialog('close');
});
return false;
});
});
window.RCC = window.RCC || {};
})(window);
这是带有验证的.js:
var $ = jQuery;
$.validator.addMethod('mypassword', function (value, element) {
return this.optional(element) || (value.match(/[a-zA-Z]/) && value.match(/[0-9]/));
},
'Password must contain at least one number.');
$(document).ready(function () {
$("#form1").validate({
rules: {
ChgPass$CurrentPass: {
required: true
},
ChgPass$NewPass: {
required: true,
minlength: 8,
maxlength: 16,
mypassword: true
},
ChgPass$ConfirmPass: {
equalTo: "#ChgPass_NewPass"
}
}
});
});
如何禁用“modalChgPass”以允许“modalActive”和“modalEdit”处理?预先感谢您的协助。问候,