jquery - jQuery-UI .dialog("moveToTop") 即使成功运行也会引发错误
问题描述
在我打开 Jquery 对话框后,我在调用 dialog("moveToTop") 时遇到问题。我之所以这么称呼它是因为我的模态对话框出现在叠加层下(它们需要附加到与叠加层不同的堆叠上下文中的特定表单)并且所有尝试手动强制 z-index各种元素都没有奏效。使叠加层不可见是不可接受的。
我希望在打开的任何 jquery-ui 对话框上调用 .dialog("moveToTop") :
$(document).on("dialogopen", ".ui-front", function (event, ui) {
$(document).dialog("moveToTop");
});
这似乎有效。我的对话框现在位于叠加层之上。但我在控制台中收到此错误:
Uncaught Error: cannot call methods on dialog prior to initialization;
attempted to call method 'moveToTop'
at Function.error (jquery-1.10.2.min.js:21)
at HTMLDocument.<anonymous> (jquery-ui.min.js:6)
at Function.each (jquery-1.10.2.min.js:21)
at init.each (jquery-1.10.2.min.js:21)
at init.t.fn.(:52727/anonymous function) [as dialog] (http://localhost:52727/scripts/jquery-ui/jquery-ui.min.js:6:5357)
at HTMLDivElement.<anonymous> (cmsfunctions.js:79)
at HTMLDocument.dispatch (jquery-1.10.2.min.js:22)
at HTMLDocument.v.handle (jquery-1.10.2.min.js:22)
at Object.trigger (jquery-1.10.2.min.js:22)
at HTMLDivElement.<anonymous> (jquery-1.10.2.min.js:22)
error @ jquery-1.10.2.min.js:21
(anonymous) @ jquery-ui.min.js:6
each @ jquery-1.10.2.min.js:21
each @ jquery-1.10.2.min.js:21
t.fn.(anonymous function) @ jquery-ui.min.js:6
(anonymous) @ cmsfunctions.js:79
dispatch @ jquery-1.10.2.min.js:22
v.handle @ jquery-1.10.2.min.js:22
trigger @ jquery-1.10.2.min.js:22
(anonymous) @ jquery-1.10.2.min.js:22
each @ jquery-1.10.2.min.js:21
each @ jquery-1.10.2.min.js:21
trigger @ jquery-1.10.2.min.js:22
_trigger @ jquery-ui.min.js:6
open @ jquery-ui.min.js:10
(anonymous) @ jquery-ui.min.js:6
(anonymous) @ jquery-ui.min.js:6
each @ jquery-1.10.2.min.js:21
each @ jquery-1.10.2.min.js:21
t.fn.(anonymous function) @ jquery-ui.min.js:6
(anonymous) @ cmsfunctions.js:110
dispatch @ jquery-1.10.2.min.js:22
v.handle @ jquery-1.10.2.min.js:22
以下代码根本不会将对话框移动到叠加层之上:
$("#btnOpenDialog").click(function () {
var tmpdlg = $("#popDialog").dialog({
modal: true,
autoOpen: false,
width: 530,
height: 520,
title: "Template Picker"
});
$('#popDialog').dialog('moveToTop');
$('#popDialog').dialog('open');
tmpdlg.parent().appendTo(jQuery("form#contentform"));
// prevent the default button action
return false;
});
我尝试将事件侦听器仅附加到特定对话框,但什么也没有发生。当我使用本文开头的代码时,该对话框仅出现在叠加层上方。谁能解释错误的含义?我的代码是否在未初始化的对话框上循环?如果是这样,我怎样才能使其更具体并仍然获得预期的结果?
我将 jquery-ui 1.10.2 与 jquery 3.3.1 一起使用。我也尝试换成较低的 jquery 版本,但错误仍然存在。
解决方案
也许问题只是关于订单......
错误信息说«cannot call methods on dialog before initialization» ...
所以如果你先打开它,应该没问题。
试试下面的内容:
$("#btnOpenDialog").click(function () {
var tmpdlg = $("#popDialog").dialog({
modal: true,
autoOpen: false,
width: 530,
height: 520,
title: "Template Picker"
});
// Append
tmpdlg.parent().appendTo(jQuery("form#contentform"));
// Open
$('#popDialog').dialog('open');
// Mov to top
$('#popDialog').dialog('moveToTop');
// prevent the default button action
return false;
});
推荐阅读
- java - java中的奇怪行为
- mongodb - 等效的 BSON 文档查询
- conemu - 在我运行某些东西后,ConEmu 的历史消失了
- hibernate - 关于方言的休眠异常
- raspberry-pi - 在哪里可以看到 scratch2.0 扩展的 console.log() 输出?
- c# - 为什么 C# 不抛出异步函数的本地函数内部发生的异常?
- c# - Blazor + RPC 解决方法
- c# - 在 xamarin 表单中的滚动视图内时出现 Listview 滚动问题
- excel - Excel 2007 Transpot - 与 if 语句合并
- java - SOAPUI 使用axis2生成代码