首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress中折叠的jQuery UI折叠

Wordpress中折叠的jQuery UI折叠
EN

Stack Overflow用户
提问于 2012-09-26 10:55:32
回答 2查看 949关注 0票数 1

我试图在页面加载时实现折叠折叠,除非有人转到特定的标签页。我的手风琴还能用,但就是收不开。我使用的是Wordpress平台,我的模板显示的输出如下:

代码语言:javascript
复制
<div id="accordion" class="ui-accordion ui-widget ui-helper-reset ui-accordion-icons" role="tablist">
            <section class="post-4 page type-page status-publish hentry clearfix">
                    <h1 class="entry-title acc-header dark-side ui-accordion-header ui-helper-reset ui-state-active ui-corner-top" role="tab" aria-expanded="true" aria-selected="true" tabindex="0"><span class="ui-icon ui-icon-triangle-1-s"></span><a href="#">Boon Villas – it is all about partnership</a></h1>
                    <div class="the-content dark-side ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active" style="height: 368px; display: block; " role="tabpanel">
                    Some content 1
                    </div><!-- end #the-content-->
        </section>
                <section class="post-4 page type-page status-publish hentry clearfix">
            <h1 class="entry-title acc-header dark-side ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" role="tab" aria-expanded="false" aria-selected="false" tabindex="-1"><span class="ui-icon ui-icon-triangle-1-e"></span><a href="#6" id="6">Our Commitment</a></h1>
            <div class="the-content dark-side ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" style="height: 368px; display: none; " role="tabpanel">
                Some content 2
            </div><!-- .the-content -->
    </section>

        <section class="post-4 page type-page status-publish hentry clearfix">
            <h1 class="entry-title acc-header dark-side ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" role="tab" aria-expanded="false" aria-selected="false" tabindex="-1"><span class="ui-icon ui-icon-triangle-1-e"></span><a href="#10" id="10">Our People</a></h1>
            <div class="the-content dark-side ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" style="height: 368px; display: none; " role="tabpanel">

                Some content 3
            </div><!-- .the-content -->
    </section>

        <section class="post-4 page type-page status-publish hentry clearfix">
            <h1 class="entry-title acc-header dark-side ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" role="tab" aria-expanded="false" aria-selected="false" tabindex="-1"><span class="ui-icon ui-icon-triangle-1-e"></span><a href="#17" id="17">Languages Spoken</a></h1>
            <div class="the-content dark-side ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" style="height: 368px; display: none; " role="tabpanel">

                Some content 4

            </div><!-- .the-content -->
    </section>

</div>

我的jQuery是:

代码语言:javascript
复制
        var accOpt = {
            active: false,
            header: '.acc-header',
            navigation: true,
            event: 'mouseover',
            fillSpace: false,
            animated: 'easeslide',
            collapsible: true,
            allwayOpen: false
        };
    var accTab = <?php if ( !$_GET['id']) { echo 0;} else {echo $_GET['id'];} ?>;
    $(document).ready(function(){
        $('#accordion').accordion( accOpt );
        $("#accordion").accordion( 'activate', accTab );
    });

我使用PHP从link获取id参数,以决定应该打开哪个选项卡。问题是,如果没有id或id=0 => first标签,如何实现所有标签的折叠。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-26 20:33:26

经过重新思考,我已经让它正常工作了,代码如下:

代码语言:javascript
复制
        var tabID = <?php if ( !$_GET['id']) { echo 0;} else {echo $_GET['id'];} ?>; // set tabID to be open

    var accOpt = {
            active: false,
            header: '.acc-header',
            navigation: true,
            event: 'click',
            fillSpace: false,
            animated: 'easeslide',
            collapsible: true,
            allwayOpen: false
        };
    $('#accordion').accordion( accOpt );


    if ( tabID && tabID > 0 ) { //tabID is defined and tabID > 0 activate the tab

        $("#accordion").accordion( 'activate', tabID );
    }
票数 0
EN

Stack Overflow用户

发布于 2012-09-26 11:15:11

这应该会导致页面加载时所有内容都被“折叠”。

代码语言:javascript
复制
$("#accordion").accordion({
      active: false
});

要允许用户再次关闭它,请设置collapsible: true

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12593947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档