我有3組按鈕的行爲像單選按鈕。addClass,removeClass,如果hasClass問題
單選按鈕工作正常,但我需要刪除ID爲#filter1-none的按鈕的活動類,只要其他任何按鈕都具有活動類。最好的方式是一個if/then的解決方案,還是我可以用.filter做到這一點?
這是無線電行爲。
$('.filter .btn').click(function() {
$(this).addClass('active').siblings('.active').removeClass('active');
});
這是HTML:
<div class="btn-group pull-right filter" data-toggle="buttons-radio">
<button type="button" class="btn btn-large btn-flat" id="filter1-none">Show All</button>
</div>
<div class="btn-group pull-right mr filter" data-toggle="buttons-radio">
<button type="button" class="btn btn-large btn-flat" id="filter1-LI">LI</button>
<button type="button" class="btn btn-large btn-flat" id="filter1-LPO">LPO</button>
<button type="button" class="btn btn-large btn-flat" id="filter1-NLI">NLI</button>
</div>
<div class="btn-group pull-right mr filter" data-toggle="buttons-radio">
<button type="button" class="btn btn-large btn-flat" id="filter1-Low">Low</button>
<button type="button" class="btn btn-large btn-flat" id="filter1-Medium">Medium</button>
<button type="button" class="btn btn-large btn-flat" id="filter1-Urgent">Urgent</button>
</div>
像一個良好的開端 – simple
我將修改的答案,使之更清楚一點? – alemangui