【发布时间】:2013-03-10 04:02:09
【问题描述】:
我突然从 jQuery 得到这个错误:
错误:无法在初始化之前调用对话框上的方法;试图调用方法'close'
插件
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
jQuery 代码
我在以下函数中收到这些消息:
$(document).ready(function() {
if ($('#results').html().length != 0) {
alert('has information');
$('#dialog').dialog({
modal: true,
buttons: {
Ok: function() {
// If I use $(this).dialog($(this)).dialog('close'), the UI is displayed,
// however I do not see the OK button and no errors
$(this).dialog('close');
}
}
});
} else {
alert('has no data');
}
});
HTML
<div id="dialog" title="Server Response">
<p><span class="${icon}" style="float: left; margin: 0 7px 50px 0;"></span>
<label id="results">${results}</label>
</p>
</div>
【问题讨论】:
-
我没有收到此错误:jsfiddle.net/ztPUj。但是小提琴使用 jQuery UI 1.9.2,如果这有什么不同的话。如果不是,则必须是您未发布的其他代码导致问题,如果您不提供更多信息,我们将无法为您提供帮助。
-
那就是 jQuery UI 1.9.2 并且有效,您可以提供一个答案让我接受
-
您甚至可以考虑 1.10.2,这似乎是当前的稳定版本。
-
有没有办法在页面上指定 jquery 插件的最新稳定版本,以便自动找到它?
-
我使用的是 1.10.2,但仍然出现此错误。我的设置有点不同,但是当我调用
.dialog('close')时,对话框已经非常初始化,并且错误仍然发生。
标签: javascript jquery html jquery-ui