我有一个登录对话框,可以在用户未填写所有字段时创建警告对话框。然后点击转义将删除登录对话框而不是警告对话框。
的jquery-1.7.2.js
jQueryUI的-1.8.18.js
// alert popup
function alertMsg(szMsg)
{
$('#alertText').html(szMsg);
$('#alertPopup').dialog('open');
}
$('#alertPopup').dialog({
autoOpen: false,
width: 360,
resizable: false,
modal: true,
show: 'scale',
hide: 'scale',
buttons: {
"OK": function() {
$(this).dialog("close");
}
}
});
// login dialog
$('#loginDialog').dialog({
open: function() {
$('#company').focus();
},
autoOpen: false,
width: 360,
resizable: false,
modal: true,
show: 'scale',
hide: 'scale',
buttons: {
"Login": function() {
var szCompany = $('#company').val();
var szUser = $('#user').val();
var szPassword = $('#password').val();
if ((/^\s*$/).test(szCompany) ||
(/^\s*$/).test(szUser) ||
(/^\s*$/).test(szPassword))
{
// this is the alert call that creates the bug
alertMsg('You need to fill in Company, User,' +
' and Password');
}
else
{
$(this).dialog("close");
alertMsg(szUser + ' (who works for ' +
szCompany + ' and has a secret password of ' +
szPassword + ', which is no longer a secret)' +
' check back soon for a real login experience.');
}
},
"Cancel": function() {
$(this).dialog("close");
}
}
});
// handle enter key for login dialog
$('#loginDialog').find('input').keypress(function(e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$(this).parent().parent().parent().parent().
find('.ui-dialog-buttonpane').find('button:first').click();
return false;
}
});
答案 0 :(得分:0)
在登录对话框中将“closeOnEscape”选项设置为false,在警告对话框中设置为true(默认情况下为true)