[英]Adding active class doesn't affect toggle button in Twitter Bootstrap
I have a form with multi checkbox which is required field that I turned into twitter bootstrap toggle buttons. 我有一个带有多个复选框的表单,这是必填字段,我已将其转换为Twitter Bootstrap切换按钮。
I am trying to activate a selection button with js, by adding 'active' class to it. 我试图通过向其添加“活动”类来激活带有js的选择按钮。 I am able to add the class but when saving the form I am getting an error that the field is required. 我可以添加类,但是在保存表单时出现错误,该字段为必填字段。
What am I missing? 我想念什么?
Here is the form. 这是表格。
<div id="reminder">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="checkbox" name="reminder" id="id_reminder_1" value="1" title="Choose at least one reminder option">Now</label>
<label class="btn btn-primary">
<input type="checkbox" name="reminder" id="id_reminder_2" value="30" title="Choose at least one reminder option">30m</label>
<label class="btn btn-primary">
<input type="checkbox" name="reminder" id="id_reminder_3" value="60" title="Choose at least one reminder option">1h</label>
<label class="btn btn-primary active">
<input type="checkbox" name="reminder" id="id_reminder_4" value="120"
title="Choose at least one reminder option">2h</label>
<label class="btn btn-primary">
<input type="checkbox" name="reminder" id="id_reminder_5" value="1440"
title="Choose at least one reminder option">1d</label>
</div>
</div>
This is how I am adding the class: 这就是我添加课程的方式:
$('#reminder label:eq(3)').addClass('active')
You're only adding the class, but you don't actually select it. 您仅添加了类,但实际上没有选择它。 Add the selected
attribute and it will work: 添加selected
属性,它将起作用:
$('#reminder label:eq(3)').addClass('active').attr('selected',true);
Add class open
not active
to open the dropdown (if thats what you are trying to do). 添加类open
不active
打开下拉(如果多数民众赞成你正在尝试做的)。 You have to add the class to <li class='dropdown open'>
which hosts the <ul class='dropdown-menu'>
您必须将类添加到托管<ul class='dropdown-menu'>
<li class='dropdown open'>
<ul class='dropdown-menu'>
btn-primary is the css that will make your buttons blue. btn-primary是使按钮变为蓝色的CSS。 It looks like this is what you are using for inactive buttons because the way you have your code, all the buttons should be blue. 看起来这就是您用于非活动按钮的方式,因为您使用代码的方式,所有按钮都应为蓝色。 If you are trying to make the button grey because grey will be your active button, then you can use removeClass('btn-primary'). 如果您试图将按钮设为灰色,因为灰色将是您的活动按钮,则可以使用removeClass('btn-primary')。 This will turn it grey. 这将变成灰色。 Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.