javascript - 在 Twitter Bootstrap 3 中,按钮(复选框)在取消选中后保持灰色

标签 javascript jquery css twitter-bootstrap checkbox

我使用 Twitter Bootstrap 3 并有以下代码:

<div class="btn-group" id="day-group" data-toggle="buttons">
    <label class="btn btn-default">
        <input name="fruits" id="apple" value="1" type="checkbox" />Apple
    </label>
    <label class="btn btn-default">
        <input name="fruits" id="orange" value="2" type="checkbox" />Orange
    </label>
</div>

我单击“Apple”,该按钮(复选框)呈灰色。现在已经检查完毕。

然后我再次单击“Apple”。现在是未检查状态。但它仍然是灰色的。只有当我单击其他地方时,它才会变成白色,所以我可以看到,该复选框未被选中。

我希望在取消选中白色按钮(复选框)后立即看到它,而不必单击其他地方。我怎样才能做到这一点? jQuery、CSS 还是其他方式?

最佳答案

这可能与您的 HTML 不正确有关。如果您查看 forms 上的 Bootstrap 文档,您会看到他们使用以下内容作为输入。

<div class="form-group">
    <label for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
</div>

所以,修改您的以下内容

<label class="btn btn-default">
    <input name="fruits" id="orange" value="2" type="checkbox" />Orange
</label>

至此

<div class="form-group">
    <label for="orange">Orange</label>
    <input type="checkbox" class="form-control" id="orange" placeholder="Orange">
</div>

Bootstrap on form controls -> 下面是使用禁用和非禁用形式的复选框的 Bootstrap 示例

<div class="checkbox">
  <label>
    <input type="checkbox" value="">
    Option one is this and that&mdash;be sure to include why it's great
  </label>
</div>
<div class="checkbox disabled">
  <label>
    <input type="checkbox" value="" disabled>
    Option two is disabled
  </label>
</div>

关于javascript - 在 Twitter Bootstrap 3 中,按钮(复选框)在取消选中后保持灰色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40321509/

相关文章:

javascript - 单击后如何使 css 按钮保持事件状态?

javascript - 提交表单后用文本替换 html 按钮元素

javascript - 如何将浏览器控制台日志保存到我的数据库而不覆盖 console.log

javascript - 如何在下面的图上显示所有月份(轴刻度/中断)? (右)

javascript - AJAX 上传 Web 应用程序

jquery - 在鼠标悬停时使用 jquery 隐藏特定文本

jquery - 在移动 View bootstrap3 上制作 Accordion

javascript - Semantic-UI:如何更改较暗的背景颜色?

css - 如何使 div 在内部 float 的同时增加高度

javascript - Intern 真的可以在任何 Selenium 服务上运行吗?