【问题标题】:Changing from one accordion to another after clicking on a submit button inside one accordion单击一个手风琴内的提交按钮后从一个手风琴更改为另一个手风琴
【发布时间】:2014-12-06 20:42:00
【问题描述】:

代码如下:

<div class="panel-group" id="accordion">
    <div class="panel panel-default" id="panel1">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
                    Collapsible Group Item #1
                </a>
            </h4>
        </div>
        <div id="collapseOne" class="panel-collapse collapse in">
            <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            </div>
        </div>
    </div>
    <div class="panel panel-default" id="panel2">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
                    Collapsible Group Item #2
                </a>
            </h4>
        </div>
        <div id="collapseTwo" class="panel-collapse collapse">
            <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            </div>
        </div>
    </div>
    <div class="panel panel-default" id="panel3">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
                    Collapsible Group Item #3
                </a>
            </h4>
        </div>
        <div id="collapseThree" class="panel-collapse collapse">
            <div class="panel-body">
                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
            </div>
        </div>
    </div>
</div>




<!-- Post Info -->
<div style='position: fixed; bottom: 0; left: 0; background: lightgray; width: 100%;'>
    About this SO Question: <a href='http://stackoverflow.com/q/19936572/1366033'>Bootstrap3 Bind Collapse</a><br/>
    Find documentation: <a href='http://getbootstrap.com/javascript/#collapse-usage'>Bootstrap Collapse Usage</a><br/>
    Fork This Skeleton Here <a href='http://jsfiddle.net/KyleMit/kcpma/'>Bootrsap 3.0 Skeleton</a><br/>
</div>

Jsfiddle here。 我试图通过添加和删除课堂来做到这一点。第一次可以用,第二次就不行了。

【问题讨论】:

  • 我已经编辑了你的问题。问题是我在您的手风琴中看不到任何提交按钮,另一个问题是我看不到您尝试添加和删除类的确切位置。你能用完整的代码更新你的jsfiddle吗?

标签: twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

在面板中,您可以使用buttona 元素通过使用data 属性打开另一个面板,如下所示:

<button class="btn btn-default" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">Open panel 2</button>
<a class="btn btn-default" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">Open panel 3</a>    

您要求提交,在提交后您的页面重新加载(并且重新加载之前的活动面板是未知的):

现在您可以将提交操作设置为位置哈希:&lt;form id="theform" action="#collapseThree"&gt;,注意这不会触发重新加载。之后,您可以根据位置哈希打开面板:

$(window).on( 'hashchange', function(e) { $(window.location.hash).collapse(); });

对于触发页面重新加载的情况,例如将表单操作设置为 URL form id="theform" action="yourpage.html#collapseThree"&gt; 时,您也可以根据位置哈希打开面板:

if(window.location.hash) {
$(window.location.hash).collapse();
}

最后你还可以使用e.preventDefault();防止表单重新加载:

$('#theform').on('submit', function(e){
    e.preventDefault();
    $('#collapseThree').collapse();
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    相关资源
    最近更新 更多