【问题标题】:TypeError: $(...).dialog is not a function on devserverTypeError: $(...).dialog 不是 devserver 上的函数
【发布时间】:2014-06-11 13:22:17
【问题描述】:

我有一个母版页,其中包含以下 css/js:

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="resources/css/jquery-ui.css"> 

这是我用来打开弹出窗口的函数,我传递了一些参数来加载弹出窗口。

function planDataInputPopup(dialogId, formID, actionName, popHeight, popWidth, paramData) {

$(dialogId).dialog({
    autoOpen : true,width : popWidth,modal : true,dialogClass: 'no-close',
    draggable: true, resizable: true, position: [306,105],
    buttons : {
        "Create" : function() {
                if(document.getElementById("dropDownCounter").value != null){
                    document.getElementById("dropDownCounter").value=dropDownCounter+1;
                } 
                document.getElementById("inputPopupMode").value=true;
                if(paramData == 'false'){
                    submitInputFormUsingAjax(formID,actionName,"#inputFormMainDiv");
                }else{
                    submitMultipartFormUsingAjax(formID,actionName,"#inputFormMainDiv");
                }
                $(this).dialog("close");
                $(this).remove();
                //$(this).dialog("destroy");
        },

        Cancel : function() {
            $(this).dialog("close");
            $(this).remove();
            //$(this).dialog("destroy");
            return false;
        }
    },

    close : function() {
        $(this).dialog("close");
        $(this).remove();
        //$(this).dialog("destroy");
    }
});  }

以上代码在本地运行良好,但是当我部署在开发服务器上时,我收到异常 TypeError: $(...).dialog is not a function 或有时出现“$(this).dialog("destroy")”;

对话框应该关闭,但它没有在开发服务器上发生。

我没有得到什么错误。

任何帮助将不胜感激。

【问题讨论】:

标签: javascript jquery html jquery-ui


【解决方案1】:

TypeError: $(...).dialog is not a functionthe error you get out of Firefox,当你还没有加载jqueryui。其他浏览器也有同样的错误。你可以

(1) 仔细检查您的开发服务器是否与http://code.jquery.com/ui/1.10.3/jquery-ui.js 建立了有效的非防火墙连接,或者更好 -

(2) 下载a minified jquery-ui.js 并将其包含在您服务器上的third-partylib 目录中,然后从那里获取它(这是常见的做法)。


另外:调用$(this).remove() 也调用.destroy(),如果对话框仍然打开,则调用.close()。这两行:

$(this).dialog("close");
$(this).dialog("destroy");

完全没有必要,您可以在不改变任何行为的情况下安全地删除它们。本质上,您是在连续两行上调用.destroy(),因此第二次调用将导致未初始化错误

【讨论】:

  • 感谢您的回复,我如何检查我的 devserver 是否与“code.jquery.com/ui/1.10.3/jquery-ui.js”建立了非防火墙连接,我无法访问 devserver。只有,我可以提交我的代码,它会在一定的时间间隔内自动部署在开发服务器上。我只想在操作完成后关闭弹出窗口,但它没有发生..:(
  • @amitkumar12788 当您收到该错误时,您页面上的所有 javascript 都会停止运行,这比关闭弹出窗口要严重得多。关于哪个,请尝试我在第二部分中的建议:仅使用 $(this).remove()
猜你喜欢
  • 1970-01-01
  • 2014-11-18
  • 1970-01-01
  • 1970-01-01
  • 2012-10-06
  • 2016-05-07
  • 2012-04-10
相关资源
最近更新 更多