twitter-bootstrap Bootstrap 单选按钮取消选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14390675/
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
Bootstrap Radio Button Unselect
提问by Mike Flynn
I would like to select only one option below which works fine, but also to deselect an option with bootstrap making nothing selected. Is there a way to do this?
我只想在下面选择一个可以正常工作的选项,但也要取消选择一个选项,引导程序不选择任何内容。有没有办法做到这一点?
<div class="btn-group" data-toggle="buttons-radio">
<button data-toggle="button" class="btn btn-small">1</button>
<button data-toggle="button" class="btn btn-small">2</button>
<button data-toggle="button" class="btn btn-small">3</button>
</div>
回答by Manuel Ebert
You'd have to do that with Javascript:
你必须用 Javascript 来做到这一点:
$(".btn-group button").removeClass("active");
See here: http://jsfiddle.net/TrPFf/2/
回答by Marcos Garcia
If you are using Bootstrap's Button plugin, you can wrap the radio buttons in "button" labels like this:
如果您使用的是 Bootstrap 的 Button 插件,您可以将单选按钮包装在“按钮”标签中,如下所示:
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="options" id="option1"> Option 1
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option2"> Option 2
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="option3"> Option 3
</label>
</div>
This makes a more semantic HTML and it's easier to get the user input.
这使得 HTML 更具语义,并且更容易获得用户输入。

