更改同一行的值列

时间:2019-06-09 01:44:39

标签: javascript jquery

我被困在过滤器功能上。我有一个动态行,具有多个相同的类名。

<tr>
    <td class="row-col-1">CAPTAIN</td>
    <td class="row-col-2">AMERICA</td>
</tr>
<tr>
    <td class="row-col-1">BABY</td>
    <td class="row-col-2">SHARP</td>
</tr>

我设法得到了确切的值,但是我想要的是更改同一行中其他列的值。

('#table-body').find('.row-col-1').filter(function() {
    return $(this).text() === 'BABY';
});

然后我尝试使用此方法来更改其他列的值。其他列的值不变。

('#table-body').find('.row-col-1').filter(function() {
    return $(this).text() === 'BABY';
}).find('.row-col-2').text('SHARK');

1 个答案:

答案 0 :(得分:0)

您需要使用next('td')

$('#table-body').find('.row-col-1').filter(function () {
    return $(this).text() === 'BABY';
}).next('td').text('SHARK');