【问题标题】:Getting active buttons in button-group (bootstrap)获取按钮组中的活动按钮(引导程序)
【发布时间】:2013-09-29 11:46:57
【问题描述】:

我有一个按钮组,并愿意根据活动按钮更新其他一些更改字段。 见jsfiddle here

这是从文档中复制的 HTML:

<div class="btn-group arrActiviteit arrUpdate" data-toggle="buttons">
    <label class="btn btn-primary active" data-wat='foo'>
       <input type="checkbox"> Item 1
    </label>
    <label class="btn btn-primary" data-wat='bar'>
       <input type="checkbox"> Item 2
    </label>
    <label class="btn btn-primary" data-wat='something'>
      <input type="checkbox"> item 3
    </label>
    <label class="btn btn-primary" data-wat='orElse'>
      <input type="checkbox"> item 4
    </label>
</div>

Button 行的行为与应有的一样。
然后我观察.arrUpdate div 上的点击事件以进行更改。我有多个按钮组,它们都有.arrUpdate 类。这就是第二课的原因:.arrActiviteit

$('.arrUpdate').click(function(e){
   val = ''; // for holding the temporary values

   $('.arrActiviteit label').each(function(key, value){
       if(value.className.indexOf('active') >=0){
           val += value.dataset.wat
       }
   })

   // just for debug reasons.
   $('#hierHier').html(val); 

})

但似乎在点击事件触发之后添加了“活动”类。所以#hierHier中的值总是一键后,可以这么说。

我该如何解决这个问题?
或者有没有更好的方法来检索此复选框数组中的所有活动按钮?

【问题讨论】:

  • 把你的代码放在这里jsfiddle.net/hA423/2,以便我们找出问题所在。
  • 我已经更新了 jsfiddle

标签: javascript twitter-bootstrap twitter-bootstrap-3


【解决方案1】:

已解决


更新:更好的解决方案Twitter Bootstrap onclick event on buttons-radio


http://jsfiddle.net/hA423/7/

我使用超时解决了它,以使您的函数在引导事件之后运行...

一定有其他方法可以做到……

$('.btn').on('click',function(e){
  setTimeout(count);
})

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-24
  • 2021-06-10
  • 2018-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多