2015-02-19 19 views
5

Ho provato jquery datatable con tre righe colorate che si ripetono alternativamente. Ma ho ripetuto solo due righe colorate.Jquery databile con tre righe di colore

Tried jquery datatable with tri colored rows
Sto utilizzando la proprietà pari/dispari per la colorazione

$(document).ready(function() { 
    $('#example').dataTable(); 
}); 
$(document).ready(function() { 
$("#example tr:even").css("background-color", "LightYellow"); 
$("#example tr:odd").css("background-color", "LightBlue"); 
}); 
+0

È possibile utilizzare 'nth-child()', anche avere più gestori 'document.ready' in un unico file è ridondante - comprendono tutto il codice in uno solo. –

risposta

6

Non è necessario utilizzare jQuery per implementare questo CSS è molto più adatto a quel lavoro. prova questo.

/*tri color rows*/ 
table.dataTable tbody tr:nth-child(3n+1) {background-color: #FFCCCC;} 
table.dataTable tbody tr:nth-child(3n+2) {background-color: #99D6AD;} 

table.dataTable tbody tr:nth-child(3n) {background-color: #EBD6FF;} 
th { 
background: #aaf; 
} 
thead{ 
    background: #aaf; 
} 
/* End: tri color rows*/ 

check this Demo in js fiddle

+1

La risposta più efficiente, sebbene si tenga presente che non funzionerà per