jQuery TypeError: $(...).dialog is not a function Error

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19442929/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:58:58  来源:igfitidea点击:

TypeError: $(...).dialog is not a function Error

javascriptjqueryjquery-ui

提问by PythonEnthusiast

I have read threads on this topic on SO, but not able to get the required o/p. They said this problem arises because some js files are being included multiple times. But I tried removing the multiple files one-by-one, but still getting the TypeError: $(...).dialog is not a functionError. Where I'm including multiple js files? Can someone please point it out. Thanks.

我在 SO 上阅读了有关此主题的主题,但无法获得所需的 o/p。他们说出现这个问题是因为一些js文件被多次包含。但是我尝试一个一个删除多个文件,但仍然出现TypeError: $(...).dialog is not a function错误。我在哪里包含多个 js 文件?有人可以指出它。谢谢。

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

<script type="text/javascript" src="{% static "js/bootstrap.js" %}" ></script>
<script type="text/javascript" src="{% static "dashboard/js/jquery-ui-personalized-1.6rc2.min.js" %}" ></script>
<script type="text/javascript" src="{% static "dashboard/js/inettuts.js" %}" ></script>    
<script type="text/javascript" src="{% static "dashboard/js/dashboard.js" %}" ></script>

The errors that I get are :-

我得到的错误是:-

Error: Syntax error, unrecognized expression: #intro,
    ...nction(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"...    
jquery.min.js (line 4)

TypeError: t.widget.extend is not a function
    ..."drag",e,s)===!1)return this._mouseUp({}),!1;this.position=s.position}return thi...
   jquery-ui.min.js (line 5) 

回答by melancia

You have a couple of jQuery libraries being loaded on the same page (different versions of the same thing), which is wrong, unless you really need to keep old plugins working that depend on previous versions. In this specific case you would need to work out the conflicts.

您在同一页面上加载了几个 jQuery 库(同一事物的不同版本),这是错误的,除非您确实需要保持依赖于以前版本的旧插件工作。在这种特定情况下,您需要解决冲突。

That's all you need:

这就是你所需要的:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

<script type="text/javascript" src="{% static "js/bootstrap.js" %}" ></script>
<!-- Not so sure what is this, but certainly it's another jQuery UI library being loaded on top of the other one -->
<!-- <script type="text/javascript" src="{% static "dashboard/js/jquery-ui-personalized-1.6rc2.min.js" %}" ></script>-->
<script type="text/javascript" src="{% static "dashboard/js/inettuts.js" %}" ></script>    
<script type="text/javascript" src="{% static "dashboard/js/dashboard.js" %}" ></script>

Look here for the CSS stylesheet (play with the theme): http://jqueryui.com/

在这里查看 CSS 样式表(玩主题):http: //jqueryui.com/

The jQuery UI Dialog: http://jqueryui.com/dialog/

jQuery UI 对话框:http: //jqueryui.com/dialog/

UPDATE

更新

After our chat on the comments, I've found out that you're using a plugin called inettutswhich is based on really old versions of jQuery and jQuery UI libraries (1.2.x). Also, it uses a customized version of the jQuery UI which doesn't includes the dialogwidget, hence the first error message.

在我们对评论的讨论之后,我发现您正在使用一个名为的插件inettuts,该插件基于非常旧版本的 jQuery 和 jQuery UI 库 (1.2.x)。此外,它使用不包含dialog小部件的 jQuery UI 的自定义版本,因此是第一条错误消息。

You can try to adapt the plugin to work with newer versions (following the comments on its own website) or work out the conflicts and use two libraries on the same page.

您可以尝试调整插件以使用较新版本(遵循其网站上的评论)或解决冲突并在同一页面上使用两个库。

It's up to you now.

现在就看你了。

回答by TagFolks

Look at in the generated source code, then find out all the references to jquery, then check out that there is only one reference to jquery and one to jquery UI.

在生成的源码中查看,然后找出所有对jquery的引用,然后查看只有一个jquery的引用和一个jquery UI的引用。

回答by sofs1

Make sure you have the js libraries that you are referencing in jsp/html in corresponding folder. Mostly it would be WebContent folder or the path you specify in jsp. For me it was in /resources/scripts folder. Once I added the libraries there

确保您在相应文件夹中的 jsp/html 中拥有您正在引用的 js 库。大多数情况下,它是 WebContent 文件夹或您在 jsp 中指定的路径。对我来说,它在 /resources/scripts 文件夹中。一旦我在那里添加了库