以下是我的代码,
$(document).ready(function () {
$("#es").hide();
$("#n").hide();
$('input[type="radio"]').click(function () {
if (this.value === "Yes")
$("#es").show();
else if (this.value === "No")
$("#n").show();
});
});
有 2 个单选按钮用于表示是和否。如果选择“否”,则选择"is"后,仅不应该选择任何选项,但这里两个按钮都被选中。我该如何纠正这个问题?
最佳答案
只需为它们提供相同的名称。你不需要 javascript 来做到这一点。
<label><input type="radio" name="group" id="es" value="Yes"/>Yes</label>
<label><input type="radio" name="group" id="n" value="No"/>No</label>
关于jquery - Html单选按钮选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17519388/