【问题标题】:Dynamically created jQuery UI dialog error after jQuery 2.2.0 upgradejQuery 2.2.0 升级后动态创建的 jQuery UI 对话框错误
【发布时间】:2016-04-27 19:50:00
【问题描述】:

我使用 jQuery UI 1.11.4 创建了一些对话框。我正在尝试将我的 jQuery 从 1.11.3 升级到 2.2.0。尝试初始化 jQuery UI 对话框时收到错误消息。

 $deptdialog = $('<div id="deptdialog"></div>')
    .html('<iframe id="deptiframe" style="width:100%;" scrolling="no" src="" />')
    .dialog({ ... });

这样初始化后..

$deptdialog .dialog('open');

我收到了这个错误

Uncaught TypeError: Cannot read property 'pageYOffset' of null

当进入 jQuery 时,这一行出现错误

win = getWindow( doc );
top: box.top + win.pageYOffset - docElem.clientTop,

win 最终为空。有人指出我为什么会发生这种情况,或者如何解决它?是因为我在对话框窗口中加载了动态 iFrame 吗?

【问题讨论】:

    标签: javascript jquery jquery-ui iframe


    【解决方案1】:

    只有在我的 sn-p 中的文档准备好之前声明对话框对象(即:$deptdialog)时才会出错,否则它可以正常工作。

    $(function () {
      $deptdialog = $('<div id="deptdialog"></div>')
      .html('<iframe id="deptiframe" style="width:100%;" scrolling="no" src="https://en.wikipedia.org/wiki/Main_Page" />')
      .dialog({autoOpen: false});
    
      $('#btn').on('click', function(e) {
        $deptdialog.dialog('open');
      })
    });
    <link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
    <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
    <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    
    
    
    <button id="btn">Open Dialog</button>

    【讨论】:

    • 谢谢!那是我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多