如何选择每个()的第一个收音机?

时间:2012-11-21 13:06:15

标签: jquery jquery-ui jquery-plugins

选择Jquery.each

的第一个单选按钮

是否可以选择从每个div中选择第一个无线电

<div>
<table class="sortable accountTable float_left">
      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group1" checked='checked' /></td>
        <td>Organisation structure 1</td>
      </tr>
      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group2" /></td>
        <td>Organisation structure 2</td>
      </tr>

      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group3" /></td>

        <td>Organisation structure 3</td>
      </tr>
      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group4" /></td>
        <td>Organisation structure 4</td>
      </tr>
</table>
 </div>
<div>
<table class="sortable accountTable float_left">
      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group1" checked='checked' /></td>
        <td>Organisation structure 1</td>
      </tr>
      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group2" /></td>
        <td>Organisation structure 2</td>
      </tr>

      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group3" /></td>

        <td>Organisation structure 3</td>
      </tr>
      <tr>
        <td class="textlmiddle"><input name="acc_number2" type="radio" value="" rel=
        ".structure_group4" /></td>
        <td>Organisation structure 4</td>
      </tr>
</table>
 </div>
<div>
<table class="sortable accountTable float_left">
      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group1" checked='checked' /></td>
        <td>Organisation structure 1</td>
      </tr>
      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group2" /></td>
        <td>Organisation structure 2</td>
      </tr>

      <tr>
        <td class="textlmiddle"><input type="radio" value="" rel=
        ".structure_group3" /></td>

        <td>Organisation structure 3</td>
      </tr>
      <tr>
        <td class="textlmiddle"><input name="acc_number2" type="radio" value="" rel=
        ".structure_group4" /></td>
        <td>Organisation structure 4</td>
      </tr>
</table>
 </div>

这是DEMO

1 个答案:

答案 0 :(得分:6)

我相信这会奏效:

$('body > div').each(function() {
    $('input[type="radio"]', this).first().prop('checked', true);
});