点击TD,jQuery的选择单选按钮 [英] Click td, select radio button in jQuery
本文介绍了点击TD,jQuery的选择单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个小问题,一些非常基本的jQuery的,我希望能够点击一个表格单元格,然后让它自动选择里面的单选按钮。
Got a small problem with some very basic jQuery, I'd like to be able to click on a table cell, and then have it automatically select the radio button inside.
HTML
<table>
<tr>
<td>
1<br>
<input type="radio" name="choice" value="1">
</td>
<td>
2<br>
<input type="radio" name="choice" value="2">
</td>
<td>
3<br>
<input type="radio" name="choice" value="3">
</td>
</tr>
</table>
jQuery的:
jQuery:
$("td").click(function () {
$(this).closest('input:radio').attr('checked',true);
});
任何帮助真的会AP preciated,谢谢!
Any help would really be appreciated, thank you!
推荐答案
使用这个选择:
$('input:radio', this).attr('checked', true);
或使用找到
方法:
$(this).find('input:radio').attr('checked', true);
下面是你的code应该怎么是这样的:
Here is how your code should look like:
$("td").click(function () {
$(this).find('input:radio').attr('checked', true);
});
这篇关于点击TD,jQuery的选择单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文