我已经构建了一个常见的错误对话框函数来获得我的对话框的通用外观。我从函数内部调用该$.ajaxSetup.error
函数没有问题。我通过对话框上的调用添加了一个按钮。ajaxSetup.error
我的按钮将关闭对话框,当从函数调用时,角落中的 X 将关闭窗口。
如果我尝试从我的 JS(不是 AJAX 调用)中的 catch 块中调用相同的函数,则对话框会毫无问题地打开,但是当我单击按钮关闭对话框时,会出现以下错误:
0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“_focusTabbable”
这是生成我的对话框的代码:
function __renderDialogOK(data) {
// This call renders the div to be displayed within
// the dialog.
var divMessage = __renderDialogBase(data);
$(divMessage).dialog(
{
width: __getDialogWidth(),
resizeable: false,
modal: true,
hide: true,
show: true,
buttons: [
{
text: "OK",
click: function (e) {
e.preventDefault();
$(this).dialog("close");
return false;
}
}
],
open: function (e) {
$(this).parent().find("button:eq(1)").addClass('ui-state-default');
$(this).parent().find("button:eq(1)").focus();
$(this).on("keydown", function (event) {
if (parseInt(event.keyCode) === 13) {
$(this).parent()
.find("button:eq(1)").trigger("click");
return false;
}
if (event.keyCode == 27) {
$(this).parent()
.find("button:eq(1)").trigger("click");
return false;
}
});
},
close: function (e) {
$(this).off("keydown");
}
}
);
}
正如您在我的按钮中看到的那样,我尝试使用关闭对话框$(this)
。我还尝试使用函数外部的变量(全局)来存储调用返回的上下文$(divMessage).dialog(
。
这似乎只发生在 IE11 中,这对我来说很不幸,因为我的客户将其作为他们当前的公司标准。所以最后我的问题。
当您在 JavaScript 中输入 Catch 块时,所有上下文都会丢失吗?这个问题之前是否已经暴露,我只是没有看到线程?我已经阅读了许多有关此类似错误消息的其他线程,但它们似乎不像我的实例那样具体,其中许多似乎是因为对话框尚未启动。我的是。对话框出现在屏幕上。我只是无法用我的按钮关闭它。