多个按钮组 - 选择问题

时间:2016-08-25 14:06:20

标签: css twitter-bootstrap twitter-bootstrap-3

我有2个DYNAMICALLY创建的引导按钮组。当我选择一个按钮时,它可以工作。但是,只要我选择另一个按钮,在OTHER组中,它将取消选择原始按钮。所以基本上我只能选择一个按钮,即使它们位于不同的按钮组中。知道为什么吗?按钮组ID是唯一的。

<div class="container">
  <h2>Button Group</h2>
  <div class="btn-group" id="group1">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
  </div>
  <div class="btn-group" id="group2">
    <button type="button" class="btn btn-primary">Apple</button>
    <button type="button" class="btn btn-primary">Samsung</button>
    <button type="button" class="btn btn-primary">Sony</button>
   </div>
</div>

1 个答案:

答案 0 :(得分:5)

这将解决您的问题。

<div class="container">
  <h2>Button Group</h2>
  <div class="btn-group" data-toggle="buttons">
    <label for="" class="btn btn-primary">
        <input type="radio" >Apple
    </label>
    <label for="" class="btn btn-primary">
        <input type="radio" >Samsung
    </label>
    <label for="" class="btn btn-primary">
        <input type="radio">Sony
    </label>
  </div>

  <div class="btn-group" data-toggle="buttons">
     <label for="" class="btn btn-primary">
        <input type="radio" >Apple
     </label>
     <label for="" class="btn btn-primary">
        <input type="radio" >Samsung
     </label>
     <label for="" class="btn btn-primary">
        <input type="radio" >Sony
     </label>
   </div>
</div>
相关问题