【问题标题】:Jquery dialog is undefinedJquery 对话框未定义
【发布时间】:2014-09-03 04:16:28
【问题描述】:

我正在尝试在 jquery 对话框中打开 asp.net mvc 视图。

这是我试图打开对话框的视图:

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

<script type="text/javascript">
    $(function () {
        $('#my-dialog').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            modal: true
        });

        $('.modal').click(function () {
            $('#my-dialog').load(this.href, function () {
                $(this).dialog('open');
            });
            return false;
        });
    });
</script>
<div id="my-dialog"></div>

@Html.ActionLink("Add Question", "AddQuestionInPage", new { pageID = @ViewBag.PageID },new { @class = "modal" })

但它在控制台中显示此错误:

Uncaught TypeError: undefined is not a function 

它在这一行显示错误:

$(this).dialog('open');

出了什么问题?为什么对话框未定义,因为我添加了 jquery-ui 文件。 请指导我, 谢谢

【问题讨论】:

  • this 替换为#my-dialog 会发生什么?
  • @ZippyV 我尝试将 'this' 替换为 '#my-dialog' 但仍然显示相同的错误

标签: asp.net-mvc-3 jquery-ui


【解决方案1】:

当您在 jQuery 库的路径或对您获得的库的引用的排序顺序之间出现某种不匹配时,您会遇到这种情况。

看看这个,我相信它可能会有所帮助:Uncaught TypeError: undefined is not a function on loading jquery-min.js

【讨论】:

  • 脚本按以下顺序加载:
【解决方案2】:

最后我通过以下操作设法在对话框中打开视图:

在布局文件中,我以这种方式订购了脚本:

<script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.js")"></script>

正如 Karsten 建议的那样,thanx Karsten 你的回答真的很有帮助!

我替换了以下行:

$(this).dialog('open');

用这个:

$('#my-dialog').dialog();

正如 ZippyV 在评论中建议的那样。感谢 ZippyV 它帮助了! 谢谢。 .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多