gpt4 book ai didi

javascript - 一次选择一个单选按钮

转载 作者:太空宇宙 更新时间:2023-11-04 14:13:54 26 4
gpt4 key购买 nike

我想一次从三个选项中选择一个选项。

目前我可以在单击 div 时选择单选按钮,但我只想从列表中选择一个单选按钮,因此它应该切换。

在这里检查我的 fiddle :http://jsfiddle.net/wbgthtyb/

HTML:

<div class="grid-100">
<div class="tckt-tab active">
<input type="radio" name="one" value="one">one
</div>
</div>
<div class="grid-100">
<div class="tckt-tab">
<input type="radio" name="two" value="two">two
</div>
</div>
<div class="grid-100">
<div class="tckt-tab">
<input type="radio" name="three" value="three">three
</div>
</div>

JS:

$(document).ready(function () {
$(".tckt-tab").click(function () { //when click on flip radio button
if ($(this) == $(this).find('input:radio').prop('checked', false)) {
$(this).find('input:radio').prop('checked', true);
}
});

$(".tckt-tab").click(function () { //when click on flip radio button
if ($(this) == $(this).find('input:radio').prop('checked', true)) {
$(this).find('input:radio').prop('checked', false);
}
});
});

最佳答案

单选按钮必须具有相同的名称,如果您只希望其中一个可用

例子:

   <input type="radio" name="someCoolName" value="one">one
<input type="radio" name="someCoolName" value="two">two
<input type="radio" name="someCoolName" value="three">three

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

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