为什么 Firebug 错误报告显示:jQuery(“#accordion”).accordion 不是函数?
我正在使用 Joomla 框架开发一个网络应用程序。 jQuery UI 手风琴功能对我不起作用。 Firebug报告的错误是.accordion不是一个函数。我已经阅读了很多解决各种类似错误的页面,但尚未找到解决方案。
这是我的组件视图模板中的内容:
$document =& JFactory::getDocument();
$document->addScript( '/includes/js/jquery-1.4.2.js' );
$document->addScript( '/includes/js/jquery-ui-1.8.4.custom.min.js' );
JHTML::script( 'includes/js/pfm_main_ui.js', '' );
$document->addCustomTag( '<script type="text/javascript">jQuery.noConflict();</script>' );
这是我包含的 javascript (pfm_main_ui.js):
jQuery(document).ready(function() {
jQuery('#accordion').accordion(
{
header: "h2"
});
})
这里是手风琴的 html template:
<div id="accordion">
<div>
<h2><a href="#">Header 1</a></h2>
<div id="contentPanel_1">...content ...
</div>
</div>
<div>
<h2><a href="#">Header 2</a></h2>
<div id="contentPanel_2">...content ...
</div>
</div>
<div>
<h2><a href="#">Header 3</a></h2>
<div id="contentPanel_3">...content ...
</div>
</div>
<div>
<h2><a href="#">Header 4</a></h2>
<div id="contentPanel_4">...content ...
</div>
</div>
</div>
其他信息:
Joomla 默认使用 mootools,所以我必须调用 jQuery.noConflict() 才能使用 jQuery。我相信这可能是错误的来源,但无法解决。非常感谢任何帮助!
I am developing a web app using the Joomla Framework. The jQuery UI accordion function is not working for me. The error reported by Firebug is that .accordion is not a function. I have read a lot of pages addressing various similar errors but have not found a solution.
Here is what I have in the template for my component's view:
$document =& JFactory::getDocument();
$document->addScript( '/includes/js/jquery-1.4.2.js' );
$document->addScript( '/includes/js/jquery-ui-1.8.4.custom.min.js' );
JHTML::script( 'includes/js/pfm_main_ui.js', '' );
$document->addCustomTag( '<script type="text/javascript">jQuery.noConflict();</script>' );
Here is my included javascript (pfm_main_ui.js):
jQuery(document).ready(function() {
jQuery('#accordion').accordion(
{
header: "h2"
});
})
Here is the html for the accordion in the template:
<div id="accordion">
<div>
<h2><a href="#">Header 1</a></h2>
<div id="contentPanel_1">...content ...
</div>
</div>
<div>
<h2><a href="#">Header 2</a></h2>
<div id="contentPanel_2">...content ...
</div>
</div>
<div>
<h2><a href="#">Header 3</a></h2>
<div id="contentPanel_3">...content ...
</div>
</div>
<div>
<h2><a href="#">Header 4</a></h2>
<div id="contentPanel_4">...content ...
</div>
</div>
</div>
Other info:
Joomla by default uses mootools, so I have to call jQuery.noConflict() to use jQuery. I believe this may be where the error is coming from, but cannot solve. Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些想法:
快速查看源代码的 HTML 是什么样子的? (在 FF 和 Chrome 中按 Ctrl+U)JavaScript 文件是否按正确的顺序加载?
jquery-ui-1.8.4.custom.min.js
引用的自定义 JQuery UI javascript 文件可能不包含 Accordion UI 组件的类声明。尝试从 CDN 加载完整的 JQuery UI 库(此处为 Microsoft 的:http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.min.js)并查看是否可以纠正错误。A few thoughts:
What does the HTML look like with a quick view source? (Ctrl+U in FF and Chrome) Are the javascript files being loaded in the correct order?
The custom JQuery UI javascript file referenced by
jquery-ui-1.8.4.custom.min.js
may not contain the class declaration for the Accordion UI component. Try loading the full JQuery UI library from a CDN (here Microsoft's: http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.min.js) and see if that corrects the error.