gpt4 book ai didi

jquery - Html单选按钮选择

转载 作者:搜寻专家 更新时间:2023-10-31 22:14:27 25 4
gpt4 key购买 nike

以下是我的代码,

$(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>

Fiddle

关于jquery - Html单选按钮选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17519388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com