2016-04-27 127 views
0

我使用jQuery UI 1.11.4创建了几个对话框。我试图从1.11.3升级我的jQuery到2.2.0。尝试初始化我的jQuery UI对话框时收到错误消息。jQuery 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, 

胜利结束为空。任何人都指出我为什么会发生这种情况,或者如何解决这个问题?是因为我在对话窗口中加载了一个动态iFrame吗?

回答

1

只有在我的代码片段中的文档准备就绪之前声明对话框对象(即:$ 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>

+0

谢谢!这是我的问题。 –