我想一次从三个选项中选择一个选项。
目前我可以在单击 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/