twitter-bootstrap Bootstrap 3 单选按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18003183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap 3 radio button
提问by Penguinator
I'm playing with twitter bootstrap 3 and its new radio buttonsand cannot seem to get which button is checked.
我正在使用 twitter bootstrap 3 及其新的单选按钮,似乎无法检查哪个按钮被选中。
My buttons are like this:
我的按钮是这样的:
<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>
I can get whether either button is clicked through $(".btn-group").click(), but inside there I can't get which button is clicked. I'll get the 2 buttons through jquery $("input[name='inputLogType']"), and one of them will have checked:trueproperty. However when I do $("input[name='inputLogType']:checked"), nothing shows up.
我可以获得是否点击了任一按钮$(".btn-group").click(),但在那里我无法获得点击了哪个按钮。我将通过 jquery 获得 2 个按钮$("input[name='inputLogType']"),其中一个将具有checked:true属性。但是,当我这样做时$("input[name='inputLogType']:checked"),什么也没有出现。
Anyone knows what's wrong?
有谁知道出了什么问题?
采纳答案by BenjaminCorey
Are you trying to access the :checkedvalue in the click callback? If so, it's likely that the property hasn't been applied yet.
您是否尝试访问:checked点击回调中的值?如果是这样,很可能该物业尚未申请。
You can use $(event.target).find('input');to select the targeted radio button.
您可以使用$(event.target).find('input');来选择目标单选按钮。

