使用jquery查找所有td';在表中按列位置排序
我正在尝试将一个类添加到表的每一行的最后一个单元格中…这不起作用…它只将rightStyle应用于第一行(顶部)的最后一个元素使用jquery查找所有td';在表中按列位置排序,jquery,each,Jquery,Each,我正在尝试将一个类添加到表的每一行的最后一个单元格中…这不起作用…它只将rightStyle应用于第一行(顶部)的最后一个元素 搜索tds时,只需查看当前行的内部。请参见添加的内容: 您的表行也可能不都有lastIndex单元格。请尝试以下方法以提高可靠性: rows.each(function () { $(this).children("td").last().addClass(rightStyle) }); 我用了第n个孩子 $("table.scrollable td:n
搜索tds时,只需查看当前行的内部。请参见添加的内容:
您的表行也可能不都有
lastIndex
单元格。请尝试以下方法以提高可靠性:
rows.each(function () {
$(this).children("td").last().addClass(rightStyle)
});
我用了第n个孩子
$("table.scrollable td:nth-child(" + lastIndex + ")").addClass(rightStyle);
不过,这里有一些不错的替代方案 一行完成所有工作
$('table tr td:last-child').addClass(rightStyle);
// Targeting a particular column as pointed out by FiveTools
// Note that :nth-child(n) is 1-indexed
$('table tr td:nth-child(3)').addClass('highlight');
我做了与您相同的事情,但我设置了最后一个td的列宽
// SET FIRST AND LAST TD SIZE
$("tr").each(function() {
$(this).children("td:last").attr("width", 200);
});
如果不知道getLastVisibleIndex和标记中的内容,就不可能告诉您出了什么问题。
$("table.scrollable td:nth-child(" + lastIndex + ")").addClass(rightStyle);
$('table tr td:last-child').addClass(rightStyle);
// Targeting a particular column as pointed out by FiveTools
// Note that :nth-child(n) is 1-indexed
$('table tr td:nth-child(3)').addClass('highlight');
// SET FIRST AND LAST TD SIZE
$("tr").each(function() {
$(this).children("td:last").attr("width", 200);
});