twitter-bootstrap 设置引导复选框按钮的初始值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24290973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 20:59:12  来源:igfitidea点击:

Set initial value for bootstrap checkbox button

twitter-bootstrapbutton

提问by Sam

I'm using the code below to set the middle checkbox to be true but it's not working. What am I missing?

我正在使用下面的代码将中间的复选框设置为 true,但它不起作用。我错过了什么?

For demo go to http://jsfiddle.net/5sq7v/

对于演示去http://jsfiddle.net/5sq7v/

<div class="btn-group" data-toggle="buttons">
    <label class="btn btn-default">
        <input type="checkbox">Hello 1
    </label>
    <label class="btn btn-default">
        <input type="checkbox" checked="checked">Hello 2
    </label>
    <label class="btn btn-default">
        <input type="checkbox">Hello 3
    </label>
</div>

回答by Sam

Looks like you are missing the 'active' class in the second label. Is this what you were looking for?

看起来您在第二个标签中缺少“活动”类。这就是你要找的吗?

<div class="btn-group" data-toggle="buttons">
    <label class="btn btn-default">
        <input type="checkbox">Hello 1
    </label>
    <label class="btn btn-default active">
        <input type="checkbox" checked="checked">Hello 2
    </label>
    <label class="btn btn-default">
        <input type="checkbox">Hello 3
    </label>
</div>

回答by cvrebert

See Bootstrap's bleeding-edge docs:

请参阅Bootstrap 的前沿文档

Pre-checked options need .active

For pre-checked options, you must add the .activeclass to the <input>'s <label>yourself.

需要预先检查的选项 .active

对于预先检查的选项,您必须将.active类添加到<input>'s 中<label>