0

私は次のhtmlを持っています:

<table class="userenrolment ajaxactive">
<tbody>
<tr class="userinforow r0" id="user_9">
<td class="field col_userdetails cell c0" style="">
</td>
<td class="field col_enrol cell c4 lastcol" style="">
<div class="enrolment"><span>Team 1</span>
</div>
</td>
</tr>
<tr class="userinforow r1" id="user_4">
<td class="field col_userdetails cell c0" style="">
</td>
<td class="field col_enrol cell c4 lastcol" style="">
<div class="enrolment"><span>Team 2</span>
</div>
</td>
</tr>
</tbody>
</table>

jQuery を使用して、各 tr からIDを取得し、同じ行に追加したいと考えています。

私の関数は次のようになりますが、まったく機能しません。

function show_groups(){
table.find('.userinforow).each(function(){
    var text = $(this).find('#id').val();
    $('.enrolment').append('text:' + text + ' <br>');
} 
4

1 に答える 1

1

あなたが必要

function show_groups() {
    $('.userenrolment').find('.userinforow').each(function () {
        $(this).find('.enrolment').append('text:' + this.id + ' <br>');
    });
}

デモ:フィドル

于 2013-10-14T13:04:57.630 に答える