jQuery implements the method of alternating table colors
- 2020-05-12 02:09:04
- OfStack
This article illustrates an example of how jQuery implements alternate display of table colors. Share with you for your reference. The specific implementation method is as follows:
<!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>
<title>jQuery Realize the alternate display of table colors </title>
<script type="text/javascript" src="js/jquery1.3.2.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".truecolor tr:odd").addClass("color1");
jQuery(".truecolor tr:even").addClass("color2");
jQuery(".truecolor tr").hover(function(){
jQuery(this).addClass("color3")
},function(){
jQuery(this).removeClass("color3")
});
});
</script>
<style type="text/css">
.truecolor {border:1px solid #333;text-align:center;}
.truecolor th {background-color:#333; color:#FFF;}
.color1 {background-color:#DDD; color:#333;}
.color2 {background-color:#EEE; color:#333;}
.color3 {background-color:#666; color:#FFF;}
</style>
</head>
<body>
<table width="450" class="truecolor">
<thead>
<tr>
<th> blog </th>
<th> The author </th>
<th> The url </th>
</tr>
</thead>
<tbody>
<tr>
<td> The style of dance </td>
<td> The fire, </td>
<td> Interlaced color change </td>
</tr>
<tr>
<td> Zhao lei's blog </td>
<td> zhao </td>
<td> Sina weibo </td>
</tr>
<tr>
<td> Lonely square </td>
<td> Wei Chunliang </td>
<td> alumni </td>
</tr>
<tr>
<td> taobao UED</td>
<td> taobao </td>
<td> Often shopping </td>
</tr>
</tbody>
</table>
</body>
</html>
I hope this article has been helpful to your jQuery programming.