使用 jQuery 为表的第二列添加类
<table>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
</table>
table td {
background-color: green;
padding: 5px;
border: 1px solid blue;
}
.red {
background-color: red;
}
直播: http://jsfiddle.net/zCduV/1/
如何我可以使用 jQuery 添加类 .red 作为此表中的第二列(在本例中,这是 td 中 ccc 的位置)?
<table>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
<tr><td>aaa</td><td>ccc</td><td>aaa</td><td>aaa</td><td>bbb</td><td>aaa</td><td>aaa</td></tr>
</table>
table td {
background-color: green;
padding: 5px;
border: 1px solid blue;
}
.red {
background-color: red;
}
LIVE: http://jsfiddle.net/zCduV/1/
How can i add class .red with jQuery for second column in this table (in this example this is there where in td is ccc)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这也许?
http://jsfiddle.net/tdTkQ/
This maybe?
http://jsfiddle.net/tdTkQ/
通过使用 jQuery nth-child 选择器:
参考:http://api.jquery.com/nth -子选择器/
By using the jQuery nth-child selector:
Reference: http://api.jquery.com/nth-child-selector/
看一下 jQuery nth-child-selector。这就是您正在寻找的。
Take a look at jQuery nth-child-selector. This is what you are looking for.
此解决方案的示例。
Example of this solution.