jquery - 备用表行颜色更改

标签 jquery html css

我创建了一个如下表格,我想改变行的颜色。我在 head 中添加了 jquery 脚本,但它不起作用。我不知道出了什么问题。请有人解决这个问题。

提前致谢。

Home.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="jquery.dataTables.css" type="text/css" />
    <script type="text/javascript" src="jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="jquery.dataTables.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() 
{
        $('#example').dataTable();
    } );
    </script>
<script type="text/javascript">
$(function(){
  $("table.dataTable tbody tr :even").addClass("d0");
   $("table.dataTable tbody tr :odd").addClass("d1");
});
</script>
</head>
<body>
<table id="example" class="row-border" cellspacing="0" width="100%">
        <thead>
            <tr>
<th>Client</th>
                <th>Financial Year</th>
                <th>Short Description</th>
                <th>Full Description</th>
                <th>File Upload</th>
                <th>Assign TO</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
        **<tr class="d0">**
            <td>C1</td>
            <td>2014-15</td>
            <td>Hi</td>
            <td>Hello</td>
            <td>Information.pdf</td>
            <td>P232</td>
            <td>Edit</td>
        </tr>
        **<tr class="d1">**
            <td>C2</td>
            <td>2015-16</td>
            <td>Hi</td>
            <td>Hello</td>
            <td>Tech.xls</td>
            <td>P17</td>
            <td>Edit</td>
        </tr>
        </tbody>
    </table>
</body>
</html>

样式.css

table.dataTable tbody tr {
  background-color: #FFC;
}

最佳答案

您只能使用 CSS 实现:

#example tr:nth-child(odd) { background-color: #FFC }

关于jquery - 备用表行颜色更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27855818/

相关文章:

android - Galaxy S7 以相反的顺序键入文本

javascript - 如何在div中动态添加更多宽度?

Javascript 旋转两个命运之轮

javascript - HTML 音频标 checkout 现错误 - Chrome 上的音频渲染

css - 着陆页的 Angular 条件 CSS

javascript - 循环 file_put_contents 偶尔会触发 "failed to open stream"警告

javascript - 如何在以编程方式在javascript中提交表单之前检查条件

html - 图像显示在 IE11 的对话框外

css - Angular2 查询生成器模块删除按钮布局

php - 当我有权限的用户登录时,标题对我的管理页面不起作用