使用jquery按列位置查找表中的所有td
我试图将一个类添加到表格每行的最后一个单元格...这不起作用...它只将 rightStyle 应用于第一(顶)行中的最后一个元素...
//the last cell in every row all have border right
var lastIndex = getLastVisibleIndex();
var rows = $("table.scrollable tr");
rows.each(function () {
$("td:eq(" + lastIndex + ")").addClass(rightStyle)
});
I am trying to add a class to the last cell in each row of a table...this does not work...it only applies the rightStyle to the last element in the first (top) row...
//the last cell in every row all have border right
var lastIndex = getLastVisibleIndex();
var rows = $("table.scrollable tr");
rows.each(function () {
$("td:eq(" + lastIndex + ")").addClass(rightStyle)
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
一行完成所有操作...
http://jsfiddle.net/cobblers/hWqBU/
Do it all in one line...
http://jsfiddle.net/cobblers/hWqBU/
我使用了第n个孩子...
不过这里有一些很好的替代解决方案。
I used the nth-child...
Some good alternative solutions here though.
当您搜索 tds 时,您只需查看当前行内部。请参阅添加这个:
When you search for tds, you need to look only inside the current row. See the addition of this:
您的表格行也可能并非全部都有
lastIndex
单元格。尝试这个以获得更高的可靠性:It's also possible that your table rows don't all have
lastIndex
cells. Try this for more reliability:我做了和你一样的事情,但是我设置了最后一个 td 的列宽
I do the same thing that you are doing, but I set the last td's column width