stU*_*Urb 5 javascript twitter-bootstrap twitter-bootstrap-3
我有一个按钮组,我愿意根据活动按钮更新其他一些更改字段.在这里查看jsfiddle
这是从文档中复制的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>
Run Code Online (Sandbox Code Playgroud)
Button行的行为应该如此.
然后我在.arrUpdatediv 上观察点击事件以进行更改.我有多个按钮组,都有.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);
})
Run Code Online (Sandbox Code Playgroud)
但似乎在激活click事件后添加了'active'类.因此,价值#hierHier总是落后于一次点击,所以说.
我该如何解决这个问题?
或者有更好的方法来检索此复选框 - 数组中的所有活动按钮?
解决了
更新:更好的解决方案Twitter Bootstrap onclick 按钮上的事件
我使用超时解决了这个问题,使您的函数在引导事件后运行......
一定还有其他方法可以做到...
$('.btn').on('click',function(e){
setTimeout(count);
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21791 次 |
| 最近记录: |