Javascript 运行时错误:对象不支持属性或方法

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

runtime error: Object doesn't support property or method

javascriptjqueryasp.netjquery-ui

提问by user1439618

I need to create a dialog with jQuery in a pretty big project. In some places, this project uses jquery wich version is different from the one I use recent for my window.

我需要在一个相当大的项目中使用 jQuery 创建一个对话框。在某些地方,该项目使用 jquery 的版本与我最近为我的窗口使用的版本不同。

My code looks like this:

我的代码如下所示:

on ascx page

在 ascx 页面上

<html>
<head>
  <link type="text/css" href="css/jquery-ui-1.8.22.custom.css" rel="stylesheet" />
  <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
  <script type="text/javascript" src="js/jquery-ui-1.8.22.custom.min.js"></script>
  <script type="text/javascript" src="js/myjQueryCode.js"></script>
</head>
<body>
</body>
</html>

in myjQueryCode.js file

在 myjQueryCode.js 文件中

$(document).ready(function() {
    $("#dialog-form").dialog({
        autoOpen: false,
        height: 440,
        width: 500,
        modal: true,
        closeOnEscape: false
    });
});

At runtime, I get the error:

在运行时,我收到错误:

Microsoft JScript runtime error: Object doesn't support property or method 'dialog'

Microsoft JScript 运行时错误:对象不支持属性或方法“对话框”

回答by user1439618

Thanks for your answers. The problem was that the library was included multiple times in different files.

感谢您的回答。问题是该库多次包含在不同的文件中。

回答by Ty Petrice

View the page's HTML to see if there are script references to other versions of jquery in the page. If an older version is loaded after the correct version then invalid methods will throw exceptions.

查看页面的 HTML 以查看页面中是否存在对其他版本的 jquery 的脚本引用。如果在正确版本之后加载旧版本,则无效方法将引发异常。

回答by bohawi

The dialog method is from the jQuery UI library. It looks like you are using a custom version of jQuery UI, which maynot include dialog.

dialog 方法来自jQuery UI 库。看起来您正在使用自定义版本的 jQuery UI,其中可能不包括对话框。

You can customize which modules to include in jQuery UI here: http://jqueryui.com/download

您可以在此处自定义要包含在 jQuery UI 中的模块:http: //jqueryui.com/download

回答by Rusty Nail

If all of the above fails, try:

如果以上所有方法都失败,请尝试:

Check your packages installed - I resolved this issue by Installing Nuget Package: JQuery.Draggable - See: http://www.nuget.org/packages/jQuery.UI.Interactions.Draggable/

检查您安装的包 - 我通过安装 Nuget 包解决了这个问题:JQuery.Draggable - 请参阅:http://www.nuget.org/packages/jQuery.UI.Interactions.Draggable/