我也可以通过单击其他元素来展开/折叠 JQuery ui Accordion 的内容吗?

发布于 2024-10-12 10:39:37 字数 1010 浏览 7 评论 0原文

默认情况下,有内容标题来控制展开/折叠。但在我的情况下,我也可以通过其他元素展开/折叠内容。例如:

jquery ui accodion代码的基本结构:

<script>
    $(function() {
        $( "#accordion" ).accordion();
    });
    </script>



<div class="demo">

<div id="accordion">
    <h3><a href="#">Section 1</a></h3>
    <div>
        <p>
        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
        </p>
    </div>
......
</div>

和现在。我还有另一个要素,就像:

<ul id="another elements can expand/collapse too">
    <li><a href="">  expand/collapse contents of section1 of id=accordion too</a></li>
........
</ul>

非常感谢!

By default, there are headers of contents to control expand/collapse.But in my situation,I could expand/collapse the contents by another elements ,too. For example:

the basic structure of jquery ui accodion code:

<script>
    $(function() {
        $( "#accordion" ).accordion();
    });
    </script>



<div class="demo">

<div id="accordion">
    <h3><a href="#">Section 1</a></h3>
    <div>
        <p>
        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
        </p>
    </div>
......
</div>

and now. I have another elements,just like :

<ul id="another elements can expand/collapse too">
    <li><a href="">  expand/collapse contents of section1 of id=accordion too</a></li>
........
</ul>

thank you very much!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

ˇ宁静的妩媚 2024-10-19 10:39:37

更新 JQuery UI 后,手风琴上没有“活动”方法。因此,要折叠所有手风琴,请使用:

$('.accordion').accordion('option', {active: false});

After update of JQuery UI there is no "active" method on accordion. So, to collapse all accordions use:

$('.accordion').accordion('option', {active: false});
陌路黄昏 2024-10-19 10:39:37

折叠手风琴选项卡:

$('.accordion').accordion('activate', false );

展开第一个手风琴选项卡:

$('.accordion').each(function (idx, item) {
    if ($(item).accordion("option", "active") === false) {
        $(item).accordion('activate', 0);
    }
});

Collapse accordion tab:

$('.accordion').accordion('activate', false );

Expand first accordion tab:

$('.accordion').each(function (idx, item) {
    if ($(item).accordion("option", "active") === false) {
        $(item).accordion('activate', 0);
    }
});
回眸一遍 2024-10-19 10:39:37

您可以使用 .activate 并传入 false 来以编程方式折叠所有元素。由于您一次只能打开一个元素,因此这将折叠显示该链接的任何打开的元素。仅当您将 collapsible 设置为 true 时,此功能才有效。

您可以传入要展开的其他元素,以便在单击时展开该元素。

You can use .activate with false passed in to collapse all elements programmatically. Since you only ever have one element open at a time, this will work to collapse whatever element is open showing that link. This will only work if you have collapsible set to true.

You can pass in what other element you want to expand to expand that element on click.

阿楠 2024-10-19 10:39:37

我在手风琴最初加载后折叠/展开时遇到了麻烦。为了解决这个问题,我使用了:

$('#accordionId h3').click();

...它模仿单击标题区域并强制切换激活类。

感觉就像是黑客攻击,但它确实有效,贝斯特。

I to had trouble getting the Accordions to collapse/expand after they were initially loaded. To get around this I used:

$('#accordionId h3').click();

...which mimics clicking the header area and will force toggle the activation classes.

Felt like a hack, but it's what worked, Best.

冷弦 2024-10-19 10:39:37

使用 Bootstrap:

    //To Expand
    var elem  = $(this).find('.accordionElement');
    elem.addClass("in");
    elem.attr("style","");
    elem.attr("aria-expanded",true);

那么你可以使用以下方法折叠:

    var elem  = $(this).find('.accordionElement');
    elem.removeClass("in");
    elem.attr("style","height: 0px;");
    elem.attr("aria-expanded",false);

Using Bootstrap:

    //To Expand
    var elem  = $(this).find('.accordionElement');
    elem.addClass("in");
    elem.attr("style","");
    elem.attr("aria-expanded",true);

then you could collapse using:

    var elem  = $(this).find('.accordionElement');
    elem.removeClass("in");
    elem.attr("style","height: 0px;");
    elem.attr("aria-expanded",false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文