jQueryUI-未捕获的异常:无法调用方法 [英] jQueryUI - uncaught exception: cannot call methods
问题描述
我对jQuery非常陌生,并尝试在我的PHP应用程序中运行一个非常简单的jQueryUI对话框.在Firebug控制台中,出现错误:
I'm very new to jQuery and trying to run a pretty simple jQueryUI dialog box in my PHP application. In firebug console I get the error:
uncaught exception: cannot call methods on dialog prior to initialization; attempted to call method 'open'
这是我的代码:
$(function() {
$( "#dialog" ).dialog({
autoOpen: false,
show: "blind",
hide: "explode"
});
$( "#opener" ).live('click',function() {
$( "#dialog" ).dialog( "open" );
return false;
});
});
我对该错误进行了一些谷歌搜索,但没有出现太多,除了jquery.ui.js
生成错误的原因是:
I did some googling on the error and not much turned up, except that jquery.ui.js
is generating the error with:
if ( isMethodCall ) {
this.each(function() {
var instance = $.data( this, name );
if ( !instance ) {
throw "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'";
}
...
有什么想法吗?感谢您提供有关此错误消息是什么以及如何解决它的帮助.
Any ideas? I appreciate any help on what this error message is and how to resolve it.
更新:我尝试注释掉显示/隐藏"选项,但这对我的问题没有任何影响.以下是HTML:
UPDATE: I tried commenting out the show/hide options and that did not have any effect on my problem. Below is the HTML:
<div class="demo">
<div id="dialog" title="Basic dialog">
<p>This is an animated dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
<button id="opener">Open Dialog</button>
</div><!-- End demo -->
此HTML包含在一个PHP文件中,该文件包含在另一个PHP文件中.
This HTML is included in a PHP file, which is INCLUDED in another PHP file.
推荐答案
好的,这与以下事实有关:我将对话框DIV放在了我的JS尚未加载时的PHP文件上.已加载.因此,我将对话框的DIV移到了更高的页面,并且该按钮现在在我的应用程序中的任何页面上都可以使用.我希望这对其他人有帮助.
OK, it had to do with the fact that I was putting the dialog DIV on a PHP file that hadn't been loaded yet at the time my JS was loaded. So I moved the DIV for the dialog box up to a higher page, and the button works on any page throughout my app now. I hope this helps someone else.
这篇关于jQueryUI-未捕获的异常:无法调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!