简体   繁体   English

在Twitter Bootstrap手风琴中选择行

[英]Select row in twitter bootstrap accordion

I am trying to change the style of a class inside the collapse link of a twitter bootstrap accordion. 我正在尝试在twitter引导手风琴的折叠链接中更改类的样式。 But when I change the style it changes the style of all the rows. 但是,当我更改样式时,它将更改所有行的样式。 I want to select only the one I clicked. 我只选择我单击的那个。

HTML: HTML:

<div class="panel-group" id="accordion">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
          <div class="test"></div>Collapsible Group Item #1 
          </a><i class="indicator glyphicon glyphicon-chevron-down  pull-right"></i>
      </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">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
           <div class="test"></div>Collapsible Group Item #2 
        </a><i class="indicator glyphicon glyphicon-chevron-up  pull-right"></i>
      </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">
    <div class="panel-heading">
      <h4 class="panel-title">
        <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseThree">
          <div class="test"></div>Collapsible Group Item #3 
        </a><i class="indicator glyphicon glyphicon-chevron-up pull-right"></i>
      </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>

JS: JS:

$('#accordion').on('show.bs.collapse', function () {
  var collapsing = $(this).data("toggle", "collapsing");
  collapsing.find(".test").html("Test");
})

#vacancy_panel is the id of the whole accordion. #vacancy_panel是整个手风琴的ID。 Inside the a tag there is a div with the class plus_icon. 在标签内有一个带有plus_icon类的div。

JSFiddle: http://jsfiddle.net/R6EAW/261/ JSFiddle: http : //jsfiddle.net/R6EAW/261/

I want only the test class of the clicked row content to change to test in this fiddle. 我只希望单击的行内容的测试类更改为在此小提琴中进行测试。

What I don't want to do is use the id of the row. 我不想做的是使用该行的ID。

If you can wait for the end of animation you can use : 如果您可以等待动画结束,则可以使用:

$('#accordion').on('shown.bs.collapse', function () {
  var collapsing = $(this).data("toggle", "collapsing");
  $(".panel-collapse.in").prev().find('.test').html("Test");
})

Fiddle : http://jsfiddle.net/R6EAW/262/ 小提琴http : //jsfiddle.net/R6EAW/262/

UPDATE UPDATE

If you absolutely need to perform it before collapse action, one way is to perform it on the click action... 如果您绝对需要在合拢操作之前执行该操作,则一种方法是在单击操作上执行该操作...

Fiddle : http://jsfiddle.net/R6EAW/263/ 小提琴http : //jsfiddle.net/R6EAW/263/

JS : JS

$('[data-toggle="collapse"]').on('click', function(){
    $heading = $(this).parent().parent();
    $panel = $heading.next();
    if(!$panel.hasClass('in'))
    {
        $heading.find('.test').html("Test");
    }
});

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

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