c# - 如何将CSS应用于表格行

标签 c# jquery asp.net html

我需要为我的 html 表格的交替行应用背景颜色。

我当前的代码:

.licList
    {
        width: 100%;
        border: 1px solid #f7f7f7;
        text-align: center;
        border-collapse: collapse;
    }

    .licList th
    {
        font-weight: bold;
        background-color: #dbdbdb;
        border-bottom: 1px solid #f1f1f1;
        padding: 4px 5px;
    }

    .licList td
    {
        padding: 4px 5px;
    }

    .odd
    {
        background-color: #ffffff;
    }
    .odd td
    {
        border-bottom: 1px solid #cef;
    }

jquery 是

    $(document).ready(function () {
        $("licList:tr:odd").addClass("odd");
    });

我确定上面的 jquery 不正确我在单个页面中有多个表所以我不能申请

$(document).ready(function(){
    $("tr:odd").addClass("odd");
});

所以我的问题是如何解决这个问题????

最佳答案

jquery is not correct I've multiple tables in single page so I can't apply

为您的表分配一个 id/class 并访问该表下的行。假设你的表有 id tbl

Live Demo

<table id="tbl">
   <tr>
        <td>1</td>
        <td>1</td>
   </tr> 
   <tr>
        <td>1</td>
        <td>1</td>
   </tr> 
</table>

$(document).ready(function(){
    $("#tbl tr:odd").addClass("odd");
});

关于c# - 如何将CSS应用于表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14557566/

相关文章:

C# MySQL 从与另一个匹配的列中检索值

c# - 在 C# 中解析日期/时间的最宽松方法?

javascript - NVD3 加载时重绘图表 'show'

c# - 使用 C# 检查 url 中是否存在非值查询字符串

c# - 泛型方法正在拾取基类的类型

javascript - jQuery 持久非事件绑定(bind)

php mysql bootstrap行按钮/div高度

更新面板中的 Javascript 在部分回发后不起作用

c# - 自定义 ASP.NET 控件中的 Begin/EndRequestHandler 多个处理程序

asp.net - Entity Framework 支持用户定义的数据类型吗?