javascript - Jquery对话框错误: cannot call methods on dialog prior to initialization; attempted to call method 'close'

标签 javascript jquery jquery-ui-dialog

我收到以下错误: 未捕获错误:在初始化之前无法调用对话框上的方法;尝试调用方法“close”

当使用以下 jquery 脚本时:

http://rigoneri.github.io/timeout-dialog.js/js/timeout-dialog.js

The specific errors in dev tools are here

我在这里调用该函数:

    $(function () {
     $("#timeout-example").click(function(e) {
       e.preventDefault();
       $.timeoutDialog({timeout: 1, countdown: 60, logout_redirect_url: 'https://google.com', position: 'absolute', restart_on_yes: false});
     });
    }); 

根本无法让它发挥作用

最佳答案

timeout-dialog.js 插件可能无法从 jQuery 1.7 开始工作。在这个插件的官方存储库中有一个待处理的 Pull Request用于合并,并且修复了您的错误。

您应该下载timeout-dialog.js文件到本地资源,然后修改 timeout-dialog.js 文件中的函数 destroyDialog ,如下所示:

    destroyDialog: function() {
      if ($("#timeout-dialog").length) {
       //$(this).dialog("close");
         $("#timeout-dialog").dialog("close");
        $('#timeout-dialog').remove();
      }
    },

关于javascript - Jquery对话框错误: cannot call methods on dialog prior to initialization; attempted to call method 'close' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35528166/

相关文章:

jQuery::-选择器与类选择器

asp.net-mvc - Knockout Js、JQuery UI 对话框和部分 View

javascript - 将 CSS attr() 与样式化组件一起使用

javascript - 如何使用 AddThis 小部件提高页面加载速度?

javascript - 用于检查字符串数组中的重复项的更好代码

javascript - 我如何用简写函数编写这段代码?

javascript - 如何将数字分解为数字值?

javascript - 显示幻灯片编号 orbit.js foundation 6 zurb

javascript - 无法使用 jquery 和 php $_GET 导出 html 表

当存在滚动条时,jQuery UI 模式对话框背景不会使页面背景底部变暗