首页 > 解决方案 > div.dialog 不是 Modal Popup JQuery 3.5.1 中的函数

问题描述

所以决定更新我项目中的一些包,但总是有问题。我有一个设置,其中一个链接会弹出一个带有.chtml文件的模式对话框。我使用了一个名为 ModalDialogExtentions 的助手,它调用了一个名为 modaldialog.js 的 Javascript 文件。当我更新 JQuery 和 Bootstrap 时,虽然我不相信更新 bootstrap 与它有任何关系,但我的模态显示在页面底部 - 就像卡住一样。

我在控制台窗口中收到一个错误,上面写着modaldialog.js:30 Uncaught TypeError: div.dialog is not a function这让我想到了这一点:

function openModalDialog(dialogDivId, title) {
var div = $("#" + dialogDivId);
div.dialog({
    title: title,
    close: new Function("clearModalDialog('" + dialogDivId + "');"),
    modal: true,
    width: "auto",
    height: "auto",
    resizable: true 
});

setFormDataAjaxAttributes(dialogDivId);

}

有谁知道这个版本的 JQuery 发生了什么变化?原始版本是 1.10.2。我知道我已经将它更新到 3.xx 并且运行良好。但这个版本没有。它还在控制台中提到了这个文件JQuery.unobtrusive-ajax.js。我也更新了这个。

完整的控制台错误:

modaldialog.js:30 Uncaught TypeError: div.dialog is not a function
at openModalDialog (modaldialog.js:30)
at HTMLAnchorElement.eval (eval at getFunction (jquery.unobtrusive-ajax.js:34), <anonymous>:3:1)
at Object.success (jquery.unobtrusive-ajax.js:105)
at c (jquery-3.5.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.5.1.min.js:2)
at l (jquery-3.5.1.min.js:2)
at XMLHttpRequest.<anonymous> (jquery-3.5.1.min.js:2)

谢谢你的帮助!

更新:

这是模态对话框扩展之一:

 public static MvcHtmlString ModalDialogActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string dialogTitle, string CssClass)
    {
        var dialogDivId = Guid.NewGuid().ToString();

        return ajaxHelper.ActionLink(linkText, actionName, routeValues: null,
                ajaxOptions: new AjaxOptions
                {
                    UpdateTargetId = dialogDivId,
                    InsertionMode = InsertionMode.Replace,
                    HttpMethod = "GET",
                    OnBegin = string.Format(CultureInfo.InvariantCulture, "prepareModalDialog('{0}')", dialogDivId),
                    OnFailure = string.Format(CultureInfo.InvariantCulture, "clearModalDialog('{0}');alert('You are not authorized to access this area!')", dialogDivId),
                    OnSuccess = string.Format(CultureInfo.InvariantCulture, "openModalDialog('{0}', '{1}')", dialogDivId, dialogTitle)
                }, htmlAttributes: new { @class = CssClass });

    }

标签: javascriptjqueryjquery-plugins

解决方案


我遇到了对话框未打开的相同问题,当我调试事物并发现哪个是我的 Jquery 库时,我将 Jquery 和 Jquery min 库从 1.8 更新到 3.5.1,因为 Jquery 3.5.1 不再支持 Jquery 对话框,

由于不推荐使用某些库函数,例如 MISE 和 curCSS,我通过修复这些来解决它

jQuery.browser = {};
(function () {
    jQuery.browser.msie = false;
        jQuery.browser.msie = true;
        jQuery.browser.version = RegExp.$1;
    }
    
    jQuery.curCSS = function(element, prop, val) {
        return jQuery(element).css(prop, val);
    };

推荐阅读