我正在尝试将一个类添加到特定类中 tr 内的第一个 td 。但是由于某种原因,它仅将此类添加到第一个 tr 中的第一个 td - 而不是每个 tr 中的第一个 td
$("#appendTD").find("#gridFormInformation").children(0).children().each(
function() {
if ($("#appendTD").find('tr').filter(function() { return $(this).attr('class') == 'ui-widget-content ui-subtblcell'; }).children("td:eq(0)").addClass("leftbord"));
}
);
但是当我通过删除 ""td:eq(0)" 来更改上述内容时,它会将此类添加到每个 tr 中的每个 td ...那我做错了什么?
下面的标记示例
<td id="appendTD">
<table id="gridFormInformation">
<tbody>
<tr><th>1</th><th>2</th><th>3</th></tr>
<tr class="ui-widget-content ui-subtblcell"><td>1</td><td>2</td><td>3</td></tr>
<tr class="ui-widget-content ui-subtblcell"><td>1</td><td>2</td><td>3</td></tr>
<tr class="ui-widget-content ui-subtblcell"><td>1</td><td>2</td><td>3</td></tr>
</tbody>
</table>
</td>