我在表格中有这样的单选按钮
<form>
<table class="table table-hover flights_table">
<tr>
<td>
<input type="radio" class="flight" name="flight" />
</td>
<td>Fare type</td>
<td>Price</td>
<td>dep</td>
<td>Arrival</td>
</tr>
<tr>
<td>
<input type="radio" class="flight" name="flight" />
</td>
<td>Fare type</td>
<td>Price</td>
<td>dep</td>
<td>Arrival</td>
</tr>
<tr>
<td>
<input type="radio" class="flight" name="flight" />
</td>
<td>Fare type</td>
<td>Price</td>
<td>dep</td>
<td>Arrival</td>
</tr>
</table>
</form>
和 jQuery 代码
$('.flights_table tr').click(function (e) {
//$('.flight').attr('checked', false);
$(this).find('.flight').attr('checked', true);
});
目的是在单击 radio 所在的行时选择它,并且它可以工作,但每个 radio 只能运行一次。
例如,您选择第一个,然后单击第二个,如果您尝试再次选择第一个,则不起作用。
我使用的解决方案被接受为 this question 中的工作但不再完美地工作。
我也尝试用removeAttr代替注释行,结果相同。
最佳答案
试试这个
$('tr').click(function (e) {
$(this).$(input:radio).prop('checked', true);
});
关于jquery - 单击父级时选择 radio ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15983963/