内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/14061123/jquery-selector-to-grab-cells-in-the-same-column
给定一个多行多列表,如何选择与任意单元格(例如点击的单元格)相同列中的所有单元格.
就像是:
$("td").click(function(){
var columnNo = $(this).columnNo?
$(this).closest("table").find("tr td:eq("+columnNo+")").css("color", "red");
});
我需要这样做,而不必单独命名列.例如.它应该适用于简单的通用表标记,而不需要额外的类或ID.
您的尝试是正确的,所有您需要做的是使用
.index
找到列号 –<td>的索引在行内.您还需要使用 nth-child-selector
来匹配其他<td>的列索引.元素. $("td").click(function(){
var columnNo = $(this).index();
$(this).closest("table")
.find("tr td:nth-child(" + (columnNo+1) + ")")
.css("color", "red");
});
代码日志版权声明:
翻译自:http://stackoverflow.com/questions/14061123/jquery-selector-to-grab-cells-in-the-same-column
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Hit Refresh
Satya Nadella、Greg Shaw / HarperBusiness / 2017-9-26 / USD 20.37
Hit Refresh is about individual change, about the transformation happening inside of Microsoft and the technology that will soon impact all of our lives—the arrival of the most exciting and disruptive......一起来看看 《Hit Refresh》 这本书的介绍吧!
RGB转16进制工具
RGB HEX 互转工具
在线进制转换器
各进制数互转换器