jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jQuery:突出显示偶数列(不是行)大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用jQuery为偶数(或奇数)表列着色?
(不手动添加类)

我的标记是:

<table>
   <caption>Table caption</caption>
   <thead>
   <tr><th scope="col">Table header 1</th><th scope="col">Table header 2</th><th scope="col">Table header 3</th><th scope="col">Table header 3</th></tr>
   </thead>
   <tbody>

        <tr><th scope="row">Table row header</th><td>Table data</td><td>Table data</td><td>Table data</td></tr>
        <tr><th scope="row">Table row header</th><td>Table data</td><td>Table data</td><td>Table data</td></tr>
        <tr><th scope="row">Table row header</th><td>Table data</td><td>Table data</td><td>Table data</td></tr>

        <tr><th scope="row">Table row header</th><td>Table data</td><td>Table data</td><td>Table data</td></tr>
   </tbody>
</table>

(它可能包含也可能不包含范围属性标签)

解决方法

您可以使用 :nth-child() selector

$('table tr :nth-child(2n)').css('BACkground-color','#eee');

You can see a demo here中,无论该单元是否是第一个,该版本都进行了列.或者< td>你可以在那里添加(例如td:nth-​​child(2n)),如果你只想做一个或另一个.如果要选择其他列,只需执行2n 1.

大佬总结

以上是大佬教程为你收集整理的jQuery:突出显示偶数列(不是行)全部内容,希望文章能够帮你解决jQuery:突出显示偶数列(不是行)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。