jQuery 未捕获的类型错误:对象 [object Object] 没有方法“对话框”

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

Uncaught TypeError: Object [object Object] has no method 'dialog'

jqueryjquery-uidialog

提问by Nollaig

I am trying to use the jQueryUI dialog in an MVC3 application but having an issue with it. The dialog I have is loading a partial view into it where the user will either edit or create a new item. This works fine but if I try to save or update the item, or if I try to close it I get the message in the title.

我正在尝试在 MVC3 应用程序中使用 jQueryUI 对话框,但遇到了问题。我的对话框正在加载一个局部视图,用户将在其中编辑或创建一个新项目。这工作正常,但如果我尝试保存或更新该项目,或者如果我尝试关闭它,我会在标题中收到消息。

I have added all of the required .js files but still getting the error. I have also used firebug but still can't find why error is happening.

我已经添加了所有必需的 .js 文件,但仍然出现错误。我也使用过萤火虫,但仍然找不到错误发生的原因。

HTML

HTML

<span class="EditLink ButtonLink" addressId="@addr.Id">Modify this Address</span>
<div id="popup"></div>

JavaScript

JavaScript

$(document).ready(function () {
    var id = 0;

    //define config object
    var dialogOpts = {
        title: "Edit item",
        modal: true,
        autoOpen: false,
        height: 500,
        width: 500,
        open: function () {
            $("#popup").load("/partialviewtoload/" + id);
        },
        buttons: {
            Cancel: function() {
                $(this).dialog('close');
            }
        }
    };

    $("#popup").dialog(dialogOpts);    //end dialog

    $('.EditLink').click(function() {
        id = $(this).attr("itemId");
        $("#popup").dialog("open");
        return false;
    });    
});

回答by Nollaig

issue was that I was referencing "jquery-1.5.1.min.js" twice. Once in the _Layout.cshtml and also in the partial view I was loading. . Removed the reference in the partial view and got it sorted.

问题是我两次引用“jquery-1.5.1.min.js”。一旦在 _Layout.cshtml 中,也在我正在加载的局部视图中。. 删除了局部视图中的引用并对其进行了排序。

回答by Iakov Mishchenko

It seems that browser have not loaded jQueryUI, ensure that it is in your DOM

浏览器似乎没有加载 jQueryUI,请确保它在您的 DOM 中

回答by Georgy Gobozov

In my case it was that

在我的情况下是这样的

you should include first grid.locale-en.js and then jquery.jqGrid.min.js.

您应该首先包含 grid.locale-en.js,然后是 jquery.jqGrid.min.js。