首页 > Web开发 > 详细

jQuery选择表格中的列

时间:2014-11-20 15:12:45      阅读:171      评论:0      收藏:0      [点我收藏+]

以选择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");

相关链接

详解CSS中:nth-child的用法

jQuery选择表格中的列

原文:http://www.cnblogs.com/njl041x/p/4110611.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!