JQuery UI 对话框 - *对话框不是函数* 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1965026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery UI dialog - *Dialog not a function* error
提问by kartikq
I am developing a site using pinax. In one of my templates I am trying to open a simple jquery dialog box. However I keep getting the "Dialog not a function" javascript error. I am using jquery 1.2.6 and jquery-ui 1.6. My javascript and HTML are as follows:
我正在使用 pinax 开发一个网站。在我的一个模板中,我试图打开一个简单的 jquery 对话框。但是,我不断收到“对话框不是函数”javascript 错误。我正在使用 jquery 1.2.6 和 jquery-ui 1.6。我的 javascript 和 HTML 如下:
<html>
<head>
<link type="text/css" href="/site_media/smoothness/ui.all.css" rel="stylesheet" />
<script src="/site_media/jquery.js" type="text/javascript"></script>
<script src="/site_media/ui/ui.core.js" type="text/javascript"></script>
<script src="/site_media/ui/ui.draggable.js" type="text/javascript"></script>
<script src="/site_media/ui/ui.resizeable.js" type="text/javascript"></script>
<script src="/site_media/ui/ui.dialog.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#dialogbox').dialog();
});
</script>
</head>
<body>
<div id="dialogbox" title="dialog title">
<p>Test dialog</p>
</div>
</body>
</html>
Can someone please explain why this is happening?
有人可以解释为什么会这样吗?
回答by Doug Neiner
I tried to duplicate your error both by using the public google versions and by downloading the legacy (1.6) version from the jQuery UI site and manually including the files. Neither caused a problem (http://jsbin.com/uloqito see it working).
我试图通过使用公共 google 版本和从 jQuery UI 站点下载旧版 (1.6) 并手动包含文件来复制您的错误。两者都没有引起问题(http://jsbin.com/uloqi可以看到它的工作原理)。
So, that means one of the following might solve your problem:
因此,这意味着以下方法之一可能会解决您的问题:
- Use a tool like Firebug for Firefox to verify each JS file is being included.
- Make sure there is no other JS on the page that could cause an error.
- Verify you have the correct versions of the files downloaded.
- 使用 Firebug for Firefox 之类的工具来验证是否包含每个 JS 文件。
- 确保页面上没有其他可能导致错误的 JS。
- 验证您下载的文件版本是否正确。
I don't know what else to tell you since the code you pasted, when paired with the right files, works perfectly.
我不知道还有什么要告诉您的,因为您粘贴的代码与正确的文件配对时可以完美运行。
回答by Sander
I had the exact same problem as the one described above (messagebox only opens once). The problem i had was that the html in the messagebox also loads jquery. Since i don't needed it i could remove it without problems. Otherwise you might have to pin down the problem a bit further.
我遇到了与上述完全相同的问题(消息框只打开一次)。我遇到的问题是消息框中的 html 也加载了 jquery。因为我不需要它,所以我可以毫无问题地删除它。否则,您可能需要进一步确定问题。
回答by Paul Gorbas
Under certain circumstances you can get this error if multible and different JQuery version are loaded at the same time.
在某些情况下,如果同时加载多个和不同的 JQuery 版本,您可能会收到此错误。
In my case I has a ASP page that used a master. My master was including JQuery 1.4.2.min My aspx page I included JQuery 1.7.2.min
就我而言,我有一个使用母版的 ASP 页面。我的主人包括 JQuery 1.4.2.min 我的 aspx 页面我包括 JQuery 1.7.2.min
When JQuery functions were called from a control, it got confused about which JQuery to use so even though that script could state that JQuery was loaded ( it could display the JQuery version ), it failed to find any JQuery functions.
当从控件调用 JQuery 函数时,它对使用哪个 JQuery 感到困惑,因此即使该脚本可以声明 JQuery 已加载(它可以显示 JQuery 版本),它也找不到任何 JQuery 函数。
When I removed my local JQuery 1.7.2.min inclusion out of my aspx file, and updated my mater from 1.4.2.min to 1.7.2.min, the problem went away.
当我从我的 aspx 文件中删除我的本地 JQuery 1.7.2.min 包含,并将我的母校从 1.4.2.min 更新到 1.7.2.min 时,问题就消失了。
回答by user1575422
The answer by Doug Neiner helped really. My case was a bit more complicated, but still comes to same point:
Doug Neiner 的回答真的很有帮助。我的情况有点复杂,但仍然是同一点:
I opened a dialog from Page A which loads Page B like this:
我从页面 A 打开一个对话框,它像这样加载页面 B:
$('#MyDiv').dialog({
autoOpen: false
})
$("#MyDiv").load("PageB.aspx", function () {
$("#MyDiv").dialog("open");
});
The problem is that both Page A and B had included jQuery. Be aware: if you are loading another page into a dialog, it does not need to include same js.
问题是页面 A 和 B 都包含了 jQuery。请注意:如果您要将另一个页面加载到对话框中,则不需要包含相同的 js。
回答by Gerhard Liebenberg
As already explained, you probably override the existing libraries.
如前所述,您可能会覆盖现有的库。
One way of dealing with it is to ensure that the correct files are loaded.
处理它的一种方法是确保加载正确的文件。
Another way is to insert an iframe between the dialog and the content in the dialog. Iframes are treated by the browser as a separate page with its own scripts. So the scripts of the content "on top of" the iframe, will be separate from the scripts of the dialog "under" the iframe.
另一种方法是在对话框和对话框中的内容之间插入一个 iframe。浏览器将 iframe 视为具有自己脚本的单独页面。因此,“在 iframe 之上”的内容脚本将与 iframe“之下”对话框的脚本分开。
回答by Striped
I just have this issue too and the only solution that works for me was to save the dialog reference like:
我也有这个问题,唯一对我有用的解决方案是保存对话框引用,如:
var confirmDialog = $( "#dialog-confirm" ).dialog({
autoOpen: false
});
$("#test").click(function () {
confirmDialog.dialog('open');
});
Otherwise, everything I've tried failed with
否则,我尝试过的一切都失败了
.dialog() is not a function error希望这有帮助。
回答by Rafiki
I had the same problem. Mine was self inflicted from a jQuery UI update from 1.11.4 to 1.12.1. I installed the upgrade using NuGet and NuGet removed the old 1.11.4 reference from my project but never added the new project reference.
我有同样的问题。我是从 1.11.4 到 1.12.1 的 jQuery UI 更新造成的。我使用 NuGet 安装了升级,NuGet 从我的项目中删除了旧的 1.11.4 引用,但从未添加新的项目引用。
Running locally the application worked great, but when deploying it the new 1.12.1 file never made it with the publish. I hope this helps someone else.
在本地运行该应用程序效果很好,但是在部署它时,新的 1.12.1 文件从未发布。我希望这对其他人有帮助。