简体   繁体   English

从其他控件关闭折叠面板(手风琴)

[英]close a collapse panel(accordion) from other control

I am trying to close and disable the accordion from a click event of a label. 我正在尝试从标签的click事件关闭和禁用手风琴。

When clicking the label. 单击标签时。 the accordion should be disabled and closed. 手风琴应该被禁用和关闭。 I can make it disabled by using addClass method 我可以使用addClass方法禁用它

$('#c5').addClass('ui-state-disabled');
<div class="accordionHeader">
    <h3 id="c5">Advance Settings (C5)</h3>
    <div class="accordionContent">my content</div>
</div>

For closing the accordion I tried using 为了关闭手风琴,我尝试使用

$('#c5').prop('active',false);
$('#c5').attr('active',false);

neither one works. 都不行。

I do not want to use before I have to call this from other control 我不想使用之前必须从其他控件调用它

$(".accordionHeader").accordion({
    header: "h3",
    collapsible: true,
    active: false
});

From the API Documentation : API文档中

Setting active to false will collapse all panels. active设置为false将折叠所有面板。 This requires the collapsible option to be true . 这要求collapsible选项为true

So, using the following HTML, 因此,使用以下HTML,

<div class="accordionHeader">
     <h3 id="c5">Advance Settings (C5)</h3>
     <div class="accordionContent">my content</div>
</div>
<label id='c5label'>Disable accordion <input type="checkbox" /></label>

this JS will start the accordion and close/disable on the first click on the label `#c5label': 此JS将启动手风琴并在第一次单击标签#c5label时关闭/禁用它:

<script>
jQuery(document).ready(function($) {
    $(".accordionHeader").accordion({ collapsible: true });
    $('#c5label').click(function(){
        if( $( ".accordionHeader" ).accordion( "option", "active") === false )
            return;

        $('#c5').addClass('ui-state-disabled');
        $( ".accordionHeader" ).accordion( "option", "active", false );
    });
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM