【发布时间】:2013-03-03 16:52:19
【问题描述】:
我以前使用过以下脚本,它运行良好。我现在收到以下错误:
Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'.
jquery-latest.js (line 507)
如果您升级到 jQueryUI 1.10.1,它不再导致错误。通常,我会放手,升级,而不用担心。这个问题是它在过去有效,那么为什么现在不让我发疯呢?我一定是在做一些与以前不同的傻事,但我看不到。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Dialog</title>
<script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<link type="text/css" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" rel="stylesheet" />
<script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js" type="text/javascript"></script>
<script>
$(function() {
$("#open").click(function(){$("#dialog").dialog('open');return false;});
$( "#dialog" ).dialog({
modal: true,
autoOpen : false,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
</head>
<body>
<button id="open">Click</button>
<div id="dialog" title="What ever"></div>
</body>
</html>
【问题讨论】:
-
如果它在较新的版本中没有问题,那一定是您正在使用的版本的错误。我知道这会让你发疯,但这就是 Web 开发人员的生活。东西在不断变化,有时甚至每小时都在变化!
-
原来它对我来说非常适合使用 jQuery 1.8.1,而不是使用最新版本的 jQuery!
-
没关系。错误一直被引入,然后在以后的版本中再次修复,但您的问题提到它在 jQuery 1.10.1 中正常工作,所以我认为它已通过错误修复解决。 1.9 中存在许多已知问题,这就是为什么 1.9.1 在不久之后发布的原因。
-
至少我不再发疯了!我现在知道它以前在相同的情况下无法正常工作,然后神秘地停止工作。
-
您是否尝试过使用他们推荐在升级到 1.9 时使用的 jQuery 迁移插件?
标签: jquery jquery-ui jquery-ui-dialog