The core JS code for the odd and even rows of the table to set different colors

  • 2020-03-30 01:05:20
  • OfStack

This is a practical function, and the experience of reading table data is obviously better after setting the odd and even rows with different colors, otherwise the data will appear very complicated and crowded (especially when the table data is crowded). Only when you really do this aspect of things when you have a strong experience, anyway, I just experienced, stay here for reference

The core JS script code is as follows (the id of the table element is adjusted according to its own situation, and jquery-1.7.min. JS in the code can be downloaded from the official website of jquery)
<script src="jquery-1.7.min.js"></script> 

//Use CSS to control the color of even and odd lines
function SetTableRowColor() 

$("#Table tr:odd").css("background-color", "#e6e6fa"); 
$("#Table tr:even").css("background-color", "#fff0fa"); 

Related articles: