我有一个jQuery确认对话框,当用户按下Enter键时,不会触发与默认按钮关联的事件;当我使用鼠标时,按钮的行为符合预期。
当我按下Enter键时,默认按钮(“取消”)确实高亮显示,但没有其他反应。
这是对话框:
以下是生成上述对话框的代码:
$(document).ready(function () {
$('#m_btnNext').click(function (e) {
var my_messages = 'warning';
if (my_messages.length > 0) {
e.preventDefault();
$('#dialog-confirm-withdraw').html(my_messages);
$("#dialog-confirm-withdraw").dialog("open");
return false;
}
return true;
});
var cascadeConfirmWithdrawMarkup = "<div id='dialog-confirm-withdraw' title='Withdraw'><p>Set on build</p></div>";
$(cascadeConfirmWithdrawMarkup).appendTo('body').hide();
$('#dialog-confirm-withdraw').dialog({ title: '<span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Withdraw Warnings',
width: 400,
height: 175,
resizable: false,
draggable: false,
modal: true,
autoOpen: false,
open: function () {
$('.ui-dialog-buttonpane button:eq(1)').focus();
},
buttons: {
"Proceed with withdraw": function () {
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
});
});
在最简单的形式下,这段代码可以正常工作,但我在我的真实表单中很难找到问题所在。
我注释掉了所有其他javascript代码,只留下上面的代码;没有错误被记录到控制台中;但什么也没有发生。
如果上述js中没有明显的错误,那么找到这个问题的最佳方法是什么?
受虐狂者可以下载完整的html页面(包括所有javascript),在这里。我使用FF的“保存为“Web Page, Complete”来创建该zip文件。
请注意,我只是在给这个表单添加功能;我并没有创建它。