教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 JQuery实现表格隔行换色(隔行变色)效果代码一例

JQuery实现表格隔行换色(隔行变色)效果代码一例

发布时间:2015-10-13   编辑:jiaochengji.com
为大家介绍一个Jquery实现的表格隔行换行(隔行变色)效果的代码,有需要的朋友,不妨参考下了。

代码如下:

<html> <head> <title>jquery实现隔行换色-www.jbxue.com</title> <style type="text/css"> /*注意选择器的层叠关系*/ .stripe_tb th { background:#B5CBE6; color:#003399; line-height:20px; height:30px; } .stripe_tb td { padding:6px 11px; border-bottom:1px solid #95bce2; vertical-align:top; text-align:center; } .stripe_tb td * { padding:6px 11px; } .stripe_tb tr.alt td { background:#ecf6fc; /*为所有偶数行加上背景色*/ } .stripe_tb tr.over td { background:#FEF3D1; /*鼠标高亮行的背景色*/ } </style> <script src="jquery-1.5.1.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $(".stripe_tb tr").mouseover(function(){ //如果鼠标移到class为stripe_tb的表格的tr上时,执行函数 $(this).addClass("over");}).mouseout(function(){ //给这行添加class值为over,并且当鼠标一出该行时执行函数 $(this).removeClass("over");}) //移除该行的class $(".stripe_tb tr:even").addClass("alt"); //给class为stripe_tb的表格的偶数行添加class值为alt }); </script> </head> <body> <table class="stripe_tb" width="50%" border="0" cellspacing="0" cellpadding="0 "> <!--用class="stripe_tb"来标识需要使用该效果的表格--> <thead> <tr> <th>姓名</th> <th>年龄</th> <th>所在城市</th> </tr> </thead> <tbody> <tr> <td>AA</td> <td>23</td> <td>北京</td> </tr> <tr> <td>BB</td> <td>22</td> <td>上海</td> </tr> <tr> <td>CC</td> <td>24</td> <td>广州</td> </tr> <tr> <td>DD</td> <td>25</td> <td>深圳</td> </tr> </tbody> </body> </html>

效果如下图所示:
表格隔行变色
经过以上的隔行变色处理,整个的表格显示清晰直观,数据也更容易识别了。
值得收藏的好代码。

您可能感兴趣的文章:
jQuery 表格隔行换色 鼠标高亮行变色的实现代码
javascript实现隔行变色函数代码一例
js 隔行变色的最简单代码
JQuery实现表格隔行换色(隔行变色)效果代码一例
JS控制表格隔行变色的实现代码
js 隔行变色与鼠标悬停自动变色的实现代码
js 隔行变色 鼠标经过变色的代码
Js实现表格隔行变色,鼠标经过时高亮显示的代码
jQuery 行背景颜色的交替显示(隔行变色)实现代码
Js与Css结合实现表格隔行换色(隔行变色)的代码

关键词: 表格  隔行变色  隔行换色   
[关闭]
~ ~