一个更好的方法来确定表中的偶数/奇数行 [英] A better way to determine even/odd rows in table

查看:148
本文介绍了一个更好的方法来确定表中的偶数/奇数行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有包含以下示例代码的网页:

Say you have a webpage with following sample code:

<tr class="even">
    <td>something1</td>
    <td colspan="1">somthing1.1</td>
</tr>


<tr class="odd">
    <td>something2</td>
    <td><b>something2.1</b></td>
</tr>

<tr class="even">
    <td>something3</td>
    <td><b>something3.1</b></td>
</tr>

这些不是在循环中,所以我必须明确说even'odd'。后来如果我们决定在something2和something3之间添加一个新行,那么我们需要为其他行改变'even''odd'。

These are not in a loop so I have to explicitly say 'even' 'odd'. Later on if we decide to add a new row between something2 and something3 then we need to change 'even' 'odd' for rest of the rows as well.

在css中有没有方法在IE6中自动执行此操作?

Is there way in css to do this automatically in IE6?

目前这是我的CSS代码

Currently this is my css code for even

.headerTable tr.even {
    font-weight : bold;
    font-size : 9pt;
    font-family : Arial,Helvetica,sans-serif,Verdana,Geneva;
    background-color: #FFFFFF;
    height: 20px;
    color: #000000;
}

我已经有jQuery

I already had jQuery

推荐答案

尝试jQuery。然后你可以这样做:

Give jQuery a try. Then you can simply do this:

   $("#myTable tbody tr:visible:even",this).addClass("even"); 
   $("#myTable tbody tr:visible:odd",this).addClass("odd");

:visible选择器不是真的必要,行隐藏,该方法仍将正常工作。

The ":visible" selector isn't really necessary, but when you filter a table by making some rows hidden, the method will still work correctly.

这篇关于一个更好的方法来确定表中的偶数/奇数行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆