jQuery 手风琴 展开全部 [英] jQuery accordion Expand All

查看:36
本文介绍了jQuery 手风琴 展开全部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个这种格式的手风琴.

<h3 class="some-class">这里还有一些其他的 span 元素</h3></div>

在我的页面中,我有一个链接,上面写着 Expand All,通过单击此链接,我希望能够展开我所有的手风琴.

函数 expandAll(count) {for (i = 0; i <= count; i++) {$(函数(){if ($("#accordion-" + i + " h3").attr("aria-selected") !== "true") {$("#accordion-" + i + " h3").click();}})}}

只有第一个手风琴在扩展.我试图在 for 循环中放一个 console.log() 来打印 i 的值,但它只打印 0 这意味着我的循环在第一次扩展后终止.我无法理解这种行为.

欢迎任何帮助.谢谢:)

试试这个:

$(".ui-accordion-content").show();

它将打开所有的手风琴.

工作小提琴

I have several accordions in this format.

<div id="accordion-0" class="jquery-accordion ui-accordion ui-widget ui-helper-reset" role="tablist">
<h3 class="some-class">Some other span elements here</h3></div>

In my page, I have a link that says Expand All, by clicking this link I want to be able to expand all my accordions.

<a href="javascript:expandAll(10);">
function expandAll(count) {
    for (i = 0; i <= count; i++) {
        $(function() {
            if ($("#accordion-" + i + " h3").attr("aria-selected") !== "true") {
                $("#accordion-" + i + " h3").click();

            }

        })
    }
}

Only the first accordion is getting expanded. I tried to put a console.log() in the for loop to print the value of i, but it is printing only 0 which means my loop is getting terminated after the first expansion. I am unable to understand this behavior.

Any help is welcome. Thanks :)

解决方案

Try this:

$(".ui-accordion-content").show();

It will open all the accordion.

Working Fiddle

这篇关于jQuery 手风琴 展开全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆