单击td,在jQuery中选择单选按钮

前端之家收集整理的这篇文章主要介绍了单击td,在jQuery中选择单选按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一些非常基本的jQuery遇到了一个小问题,我希望能够点击一个表格单元格,然后让它自动选择里面的单选按钮.

HTML

  1. <table>
  2. <tr>
  3. <td>
  4. 1<br>
  5. <input type="radio" name="choice" value="1">
  6. </td>
  7. <td>
  8. 2<br>
  9. <input type="radio" name="choice" value="2">
  10. </td>
  11. <td>
  12. 3<br>
  13. <input type="radio" name="choice" value="3">
  14. </td>
  15. </tr>
  16. </table>

jQuery的:

  1. $("td").click(function () {
  2.  
  3. $(this).closest('input:radio').attr('checked',true);
  4.  
  5. });

任何帮助真的很感激,谢谢!

解决方法

@H_404_15@ 使用此选择器:
  1. $('input:radio',this).attr('checked',true);

或者使用find方法

  1. $(this).find('input:radio').attr('checked',true);

以下是代码的外观:

  1. $("td").click(function () {
  2. $(this).find('input:radio').attr('checked',true);
  3. });

猜你在找的jQuery相关文章