jQuery Accordion if hasClass [英] jQuery Accordion if hasClass
本文介绍了jQuery Accordion if hasClass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作手风琴,我希望首先扩展具有类当前类别的H4元素。
I am trying to make a accordion, and I want the H4 element with the class current-category to be expanded first.
我的代码:
$(function() {
$( "#category-accordion" ).accordion();
if ($('h4').hasClass("current-category")) {
$( "#category-accordion" ).accordion("activate", $('.current-category')); }
});
是的我是菜鸟。
提前致谢!
推荐答案
激活
是一个事件 [docs] ,当被触发时面板已激活。我相信您想使用 有效
选项 [docs] ,它取你想要打开的元素的索引:
activate
is an event [docs] which gets triggered when a panel has been activated. I believe you want to use the active
option [docs], which takes the index of the element you want to be opened:
$("#category-accordion").accordion({
active: $("#category-accordion > div").index($('h4.current-category').next())
});
我假设你的HTML看起来像:
I assume your HTML looks like:
<div id="category-accordion">
<h4>Section 1</h4>
<div>...</div>
<h4>Section 2</h4>
<div>...</div>
</div>
jQuery文档通常包含足够的信息和示例来解决这样的问题。
The jQuery documentation usually contains enough information and examples to solve such problems.
这篇关于jQuery Accordion if hasClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文