我正在使用Twitter Bootstrap 3和其新的单选按钮进行实验,但无法确定哪个按钮被选中。
我的按钮如下:
<div class="form-group">
<label for="inputLogType" class="col-lg-2 control-label">Log type</label>
<div class="col-lg-10">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="inputLogType" id="splunk">Splunk
</label>
<label class="btn btn-primary">
<input type="radio" name="inputLogType" id="pig">PIG
</label>
</div>
</div>
</div>
我可以通过$(".btn-group").click()
得知是否有任何一个按钮被点击,但是在其中我无法得知哪个按钮被点击。我会通过jquery得到这2个按钮$("input[name='inputLogType']")
,其中一个将拥有属性checked:true
。然而,当我执行$("input[name='inputLogType']:checked")
时,没有任何内容显示。
有人知道问题出在哪里吗?
$("input[name='inputLogType']")[i].checked
是可以的,但是有没有人知道为什么我最初不能像上面展示的那样选择? - Penguinator:checked
值?如果是这样,很可能该属性尚未被应用。你可以使用$(event.target).find('input');
。 - BenjaminCoreyconsole.log
。奇怪的是它在 jsfiddle 上运行正常,但在我的应用程序中却不行。你认为这可能与 bootstrap 3 有关吗? - Penguinator