2015-01-09 10 views
1

다음과 같이 양식을 작성했으며 행 색상을 교대로 변경하려고합니다. 머리에 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> 

있는 style.css

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

사용 의사 선택기 홀수 내가 그것을 가지고도 –

답변

0

당신은 당신이 달성 할 수있는이 스타일

tr:nth-child(even) { 
    color: white; 
    background: black; 
    } 
0

을 사용할 수 있습니다 만 CSS와 :

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

이렇게 사용하면됩니다. 왜 jquery를 사용해야합니까?

table.dataTable tbody tr.d0 { 
    background-color: #FFC; 
} 
table.dataTable tbody tr.d1 { 
    background-color: #FFF; 
} 
+0

감사 :

table.dataTable tbody tr { background-color: #FFC } table.dataTable tbody tr:nth-child(2n) { background-color:grey } 

DEMO

Kiran

0

당신은 CSS 파일에 두 개의 서로 다른 클래스를 사용할 수 있습니다

.