如何使用Bootstrap Button plugin确定单击单选按钮时选中了哪个单选按钮?
无论选择哪个单选按钮,以下评估为假:
HTML
<div class="btn-group" data-toggle="buttons" id="disabled-radio-btn">
<label class="btn btn-default">
<input type="radio" name="disabled" id="disabled-yes">Yes
</label>
<label class="btn btn-default">
<input type="radio" name="disabled" id="disabled-no">No
</label>
</div>
JS
$('#disabled-radio-btn').click(function (e) {
if ($('#disabled-no:checked').length) {
$('#SSDI').hide();
}
else {
$('#SSDI').show();
}
});
答案 0 :(得分:2)
应该在uploads.forEach(function(object){
res.json({
sessionId: object.sessionId,
fileId: object.id,
path: `${baseUrl}/sessions/${object.sessionId}/files/${object.id}/tokens`
});
});
语句中{
"sessionId": "9ff1c415-2dcc-4505-8414-4391967064bc",
"fileId": "510647c3-62fc-4412-b189-a6b872606f10",
"path": "http://localhost:3001/sessions/9ff1c415-2dcc-4505-8414-4391967064bc/files/510647c3-62fc-4412-b189-a6b872606f10/tokens"
}
来检查是否选中了单选按钮。
$('#disabled-no').is(':checked')
&#13;
if
&#13;
更新:https://jsfiddle.net/7hrbcmnb/2/
在声明点击事件时使用事件委派
$('#disabled-radio-btn').click(function (e) {
if ($('#disabled-no').is(':checked')) {
$('#SSDI').hide();
}
else {
$('#SSDI').show();
}
});
答案 1 :(得分:1)
将val()
方法与checked
属性一起使用。
if($("#disabled-no:checked").val())
$('#disabled-radio-btn').click(function (e) {
if ($('#disabled-no:checked').val()) {
$('#SSDI').hide();
}
else {
$('#SSDI').show();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn-group" data-toggle="buttons" id="disabled-radio-btn">
<label class="btn btn-default">
<input type="radio" name="disabled" id="disabled-yes">Yes
</label>
<label class="btn btn-default">
<input type="radio" name="disabled" id="disabled-no">No
</label>
</div>
<div id="SSDI">SSDI THING</div>