Bootstrap单选按钮取消选择

9

我想只选择一个选项,这个选项可以正常工作,同时使用bootstrap取消选中的选项,使得没有任何选项被选中。有没有办法实现这个功能?

<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>
2个回答

3

1
第一次的选择似乎对我无效。 - Dejell

-2
如果您正在使用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>

这样可以生成更语义化的HTML,也更容易获取用户输入。


2
它如何回答他的问题? - Dejell
按钮插件可以自动处理这个问题。这也是Bootstrap文档中推荐的方式。 - Marcos Garcia

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接