jQuery Accordion - 打开页面加载的特定部分
我在页面上有一个相当基本的 jQuery Accordion 实现(使用 1.3.2、jQuery UI Core 1.72 和 jQuery UI Accordion 1.7.2),我希望在页面加载时打开第二部分。我尝试了很多方法,但似乎没有任何效果......
头脚本:
<script type="text/javascript"> $(function() {
$("#accordion").accordion({
event: "mouseover"
});
});
身体手风琴:
<div id="accordion">
<h3><a href="#">Headline 001</a></h3>
<div>
<ul>
<li><a href="#1">Link 001</a></li>
<li><a href="#2">Link 002</a></li>
</ul>
</div>
<h3><a href="#">Headline 002</a></h3>
<div>
<ul>
<li><a href="#3">Link 003</a></li>
<li><a href="#4">Link 004</a></li>
</ul>
</div>
任何帮助将不胜感激!
I have a rather basic implementation of a jQuery Accordion on a page (using 1.3.2, jQuery UI Core 1.72 and jQuery UI Accordion 1.7.2), and I wish to open the 2nd section when the page loads. i've tried numerous methods but nothing seems to work...
HEAD SCRIPT:
<script type="text/javascript"> $(function() {
$("#accordion").accordion({
event: "mouseover"
});
});
BODY ACCORDION:
<div id="accordion">
<h3><a href="#">Headline 001</a></h3>
<div>
<ul>
<li><a href="#1">Link 001</a></li>
<li><a href="#2">Link 002</a></li>
</ul>
</div>
<h3><a href="#">Headline 002</a></h3>
<div>
<ul>
<li><a href="#3">Link 003</a></li>
<li><a href="#4">Link 004</a></li>
</ul>
</div>
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
应该做的伎俩!
更新
如果这不起作用,请尝试
(注意,这更新得更快一点,感谢您的评论。说实话,它应该与“active:2”参数一起使用,不要“不知道为什么没有。)
Should do the trick!
UPDATE
if that doesn't work, try
(N.B. this is updated to be a bit faster, thanks for the comments. To be honest, it should work with the 'active: 2' parameter, don't know why it didn't.)
打开特定选项卡的正确方法:
设置选项:
或者您可以使用这样的哈希:
如果您使用,请投票;)
谢谢
proper way to open a specific tab:
Set the option:
or you could work with a hash like this:
Vote if you use ;)
Thanks
下面的方法有效吗?
Does the following work?
尝试
Try
我已经用稍微不同的方式解决了这个问题,因为我必须创建一个我们包含的menu.php,我已经包含了每个页面。在我们的项目中,有 1 个手风琴(带有 2 个子菜单的菜单元素)。因此,当访问者位于子菜单上时,手风琴会打开,并且所选链接(使用 CSS 而不是 jQuery 突出显示)处于活动状态。但是当访问者位于不同的页面时,手风琴可以正常工作。
这是 javascript:
希望您喜欢它。 =]
最好的问候! =]
I have resolved this question a little different since I had to create a menu.php which we include I have included every single page. In our project there was 1 accordion (a menu element with 2 submenus). So when the visitor is on the submenus, the accordion is open and the selected link (which are highlighted using CSS, not jQuery) active. But when the visitor is on a different page, the accordion works normally.
Here's the javascript:
Hope you like it. =]
Best regards! =]
您应该编写
active: 1
而不是 2,因为 Accordion 从 0 开始索引节,而不是从 1 开始。工作代码看起来像这样:希望它会有所帮助。
You should write
active: 1
instead of 2, because Accordion indexes sections from 0, not from one. Working code will look like that:Hope it will help a bit.
正如其他人提到的,以下内容将使其在打开时处于活动状态:
它是
active:1
因为它是手风琴索引{0,1,2,...} 的第二个;
其他答案中似乎存在一些混乱,因为元素的内容包含字符“2
”...As others have mentioned, the following will make it active on opening:
It is
active:1
since it is the 2nd of the accordion's index{0,1,2,...};
There seems to be some confusion in other answers as the element's contents contain the character "2
"...