码迷,mamicode.com
首页 > 其他好文 > 详细

实现table表格各行变色代码实例

时间:2016-02-03 20:01:07      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

实现table表格各行变色代码实例:
本章节介绍一下如何实现表格内容的隔行变色效果,这一效果的应用非常广泛,因为它有着较高的实用性,并且实现代码也比较简单,下面就通过代码实例介绍一下如何实现此效果。
代码如下:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset=" utf-8"> 
<meta name="author" content="http://www.softwhy.com/" /> 
<title>table细线表格-蚂蚁部落</title> 
<style type="text/css">  
#thetable{ 
  background-color:green; 
  font-size:12px; 
} 
#thetable th{ 
  text-align:center; 
  background-color:#CCF; 
  height:30px; 
  line-height:30px; 
} 
#thetable td{ 
  width:150px; 
  height:30px; 
  line-height:30px; 
  text-align:center; 
} 
</style>  
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script> 
<script type="text/javascript">
$(document).ready(function(){
  $("tr:odd").css("background-color","#eeeeee");
  $("tr:even").css("background-color","#ffffff");
})
</script> 
</head>  
<body>  
<table cellpadding="0" cellspacing="1" id="thetable"> 
  <tr> 
    <th>标题一</th> 
    <th>标题二</th> 
    <th>标题三</th> 
    <th>标题四</th> 
  </tr> 
  <tr> 
    <td>蚂蚁部落一</td> 
    <td>蚂蚁部落二</td> 
    <td>蚂蚁部落三</td> 
    <td>蚂蚁部落四</td> 
  </tr>
  <tr> 
    <td>蚂蚁部落一</td> 
    <td>蚂蚁部落二</td> 
    <td>蚂蚁部落三</td> 
    <td>蚂蚁部落四</td> 
  </tr>
  <tr> 
    <td>蚂蚁部落一</td> 
    <td>蚂蚁部落二</td> 
    <td>蚂蚁部落三</td> 
    <td>蚂蚁部落四</td> 
  </tr>
  <tr> 
    <td>蚂蚁部落一</td> 
    <td>蚂蚁部落二</td> 
    <td>蚂蚁部落三</td> 
    <td>蚂蚁部落四</td> 
  </tr> 
  <tr> 
    <td>蚂蚁部落一</td> 
    <td>蚂蚁部落二</td> 
    <td>蚂蚁部落三</td> 
    <td>蚂蚁部落四</td> 
  </tr> 
</table> 
</body>  
</html>

上面的代码实现了我们的要求,实现各行变色效果,代码非常简单,这里就不多介绍了,可以参阅相关阅读。
相关阅读:
1.: odd选择器可以参阅jQuery的: odd选择器一章节。
2.:even选择器可以参阅jQuery的:even选择器一章节。
3.css()函数可以参阅jQuery的css()方法一章节。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=14434

更多内容可以参阅:http://www.softwhy.com/jquery/

实现table表格各行变色代码实例

标签:

原文地址:http://www.cnblogs.com/softwhy/p/5180382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!