我创建了一个如下表格,我想改变行的颜色。我在 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/