以选择table中的第一列为例: 方式1:
$("table tr").find("td:first").html("first column");//错误写法:$("table tr td:first").html("first column");方式2:
$("table tr").each(function(){ $(this).find("td:eq(0)").html("first column"); });方式3:
$("table tr td:first-child").html("first column");方式4:
$("table tr td:nth-child(1)").html("first column");[扩展]
//选择最后一列
$("table tr td:last-child").html("last column");//选择奇数列
$("table tr td:nth-child(odd)").html("odd colunms"); $("table tr td:nth-child(2n)").html("odd colunms");//选择偶数列
$("table tr td:nth-child(even)").html("even colunms"); $("table tr td:nth-child(2n-1)").html("even colunms");相关链接
转载于:https://www.cnblogs.com/njl041x/p/4110611.html
相关资源:JAVA上百实例源码以及开源项目