1

选择第一个单选按钮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>

​这里是演示

4

1 回答 1

6

我相信这会奏效:

$('body > div').each(function() {
    $('input[type="radio"]', this).first().prop('checked', true);
});
于 2012-11-21T13:08:51.573 回答