简单的jQueryUI对话框会导致1.9错误 [英] Simple jQueryUI Dialog causes error with 1.9
本文介绍了简单的jQueryUI对话框会导致1.9错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以前使用过以下脚本,并且运行良好.我现在收到以下错误:
I've previously used the following script and it worked perfectly. I am now getting the following error:
Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'.
jquery-latest.js (line 507)
如果升级到jQueryUI 1.10.1,它将不再导致错误.通常,我只是放手去升级它,而不用担心.这个问题是过去曾经奏效,所以为什么现在不让我发疯呢?我一定在做一些与以前不同的愚蠢的事情,但是我看不到.
If you upgrade to jQueryUI 1.10.1, it no longer causes an error. Normally, I would just let it go, upgrade, and not worry about it. Problem with this one is that it worked in the past so why not now is driving me crazy? I must be doing some silly thing different than previously, but I cannot see it.
<!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>
推荐答案
我有一个类似的问题,我通过在对话框声明之外定义按钮数组来解决该问题.
I had a similar problem that i resolved by defining my button array outside of the dialog declaration.
var buttonArray = {};
buttonArray["Ok"]=function() { $( this ).dialog( "close" );}
您的选择将变为:
modal: true,
autoOpen: false,
buttons: buttonArray
这篇关于简单的jQueryUI对话框会导致1.9错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文