【发布时间】:2015-07-17 04:39:10
【问题描述】:
我基本上使用 twitter bootstrap 的 Button Group 组件使用两个单选按钮创建了一个开/关开关。
问题是当我单击“活动”(或“已选中”)单选按钮时,我希望开关触发更改。我可以通过 Javascript 做到这一点,但由于某种原因,它会在我的 JS 完成后自动点击返回。
所以基本上我点击,我的 JS 点击另一个标签,然后 Bootsrap 点击它回来。无论如何要覆盖引导行为?
HTML
<div class="btn-group sp_toggle_switch" data-toggle="buttons">
<label class="btn btn-primary btn-xs">
<input type="radio" name="display_share_btn" value="true">ON
</label>
<label class="btn btn-default btn-xs">
<input type="radio" name="display_share_btn" value="false">OFF
</label>
</div>
Javascript
$(document).on('click','.sp_toggle_switch label.active',function(){
$(this).siblings('label:not(.active)').trigger('click');
});
CSS
.sp_toggle_switch label:not(.active ) {background:#ffffff; border-color: #ccc;}
.sp_toggle_switch label:not(.active ):hover {background:#f1f1f1;}
.sp_toggle_switch label {text-indent: 99px; overflow: hidden; width: 30px;}
.sp_toggle_switch label.active {text-indent: 0px; width: 36px;}
.sp_toggle_switch.switch_sm label {width: 24px; height: 17px; font-size: 10px; line-height: 14px;}
.sp_toggle_switch.switch_sm label.active {width: 32px; }
【问题讨论】:
标签: javascript html twitter-bootstrap twitter-bootstrap-3 radio-button