简体   繁体   English

jQuery 2.2.0升级后动态创建的jQuery UI对话框错误

[英]Dynamically created jQuery UI dialog error after jQuery 2.2.0 upgrade

I created a few Dialogs using jQuery UI 1.11.4. 我使用jQuery UI 1.11.4创建了一些对话框。 I am trying to upgrade my jQuery to 2.2.0 from 1.11.3. 我正在尝试将jQuery从1.11.3升级到2.2.0。 I receive an error when trying to initialize my jQuery UI dialog. 尝试初始化jQuery UI对话框时收到错误消息。

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

After initializing it like this.. 像这样初始化之后

$deptdialog .dialog('open');

I'm receiving this error 我收到此错误

Uncaught TypeError: Cannot read property 'pageYOffset' of null

And when stepping into jQuery it errors on this line 当进入jQuery时,此行会出错

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

win ends up being null. 胜利最终为空。 Anyone point me in the direction of why this is happening, or how to fix it? 有人指出我为什么会发生这种情况,或者如何解决? Is it because I'm loading a dynamic iFrame in the dialog window? 是因为我正在对话框窗口中加载动态iFrame吗?

I get error only if I declare the dialog object (ie: $deptdialog) before document ready in my snippet, otherwise it works fine. 仅当我在片段中准备好文档之前声明对话框对象(即$ 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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM