javascript - 为什么无法在 Bootstrap radio 组中检查 radio ?

标签 javascript jquery twitter-bootstrap

无法在 Bootstrap radio 组中检查 radio 。只有 div 处于事件状态。 Link

Bootstrap 单选组:

<form>
<div class="btn-group custom-btn-group" data-toggle="buttons">
  <label class="btn btn-default active">
    <input type="radio" class="form-control" name="feature_enabled" value="1" checked> Enabled
  </label>
  <label class="btn btn-default">
    <input type="radio" class="form-control" name="feature_enabled" value="0"> Disabled
  </label>
</div>
    </form>
<p><tt id="results"></tt></p>

js

function showValues() {
    var str = $( "form" ).serialize();
    $( "#results" ).text( str );
  }
  $( "input[type='radio']" ).on( "click", showValues );
  $( "select" ).on( "change", showValues );
showValues();

最佳答案

尝试使用 change 事件,而不是 click 事件,因为您的单选按钮包含在 label 内。此布局可能会导致 click 事件不触发。

  $( "input[type='radio']" ).on( "change", showValues );

DEMO

关于javascript - 为什么无法在 Bootstrap radio 组中检查 radio ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24409378/

相关文章:

JAVASCRIPT - 变量 "i"未定义

javascript - 使用ajax刷新页面的一部分 - 不起作用

php - 使用 session 在 php 中将商品添加到购物车

html - 创建多行标题

html - 使用正确对齐的 Logo 在 Bootstrap 4 中创建页眉

javascript - 将基本标记添加到 google maps api v3

javascript - SharePoint 2010 和 "get_groups"方法

javascript - 合并 2 个类

javascript - 如何动态获取表 "Td"值

javascript - 使用 bootstrap 标签输入,mysql 提前输入