代码改变世界

Jquery点击表格单位时选中其中的Radio的三个方法

2015-08-19 10:46  假面Wilson  阅读(792)  评论(0编辑  收藏  举报

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:

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

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

$("td").click(function () {

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

 });