[英]Getting active buttons in button-group (bootstrap)
我有一個按鈕組,我願意根據活動按鈕更新其他一些更改字段。 在這里查看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>
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);
})
但似乎在激活click事件后添加了'active'類。 所以#hierHier
的值總是落后於一次點擊,所以說。
我該如何解決這個問題?
或者有更好的方法來檢索此復選框 - 數組中的所有活動按鈕?
解決了
更新:更好的解決方案Twitter Bootstrap onclick事件按鈕 - 無線電
我使用超時解決了它,使你的函數在bootstrap事件后運行...
必須有其他一些方法來做到這一點......
$('.btn').on('click',function(e){
setTimeout(count);
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.