爱程序网

表格行背景交替变色实例代码

来源: 阅读:

表格行背景交替变色实例代码:
行与行之间背景色之间交替变换能够提高辨识度,是非常人性化的举措,本章节分享一段这样的代码,希望能够给需要的朋友带来一定的帮助,代码实例如下:

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>蚂蚁部落</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
  $("tbody tr:even").css("background-color","red");
  $("tbody tr:odd").css("background-color","yellow");
});
</script>
</head>
<body>
<table border="1">
  <tbody >
    <tr>
      <td>蚂蚁部落一</td>
      <td>蚂蚁部落二</td>
      <td>蚂蚁部落三</td>
    </tr>
    <tr>
      <td>蚂蚁部落一</td>
      <td>蚂蚁部落二</td>
      <td>蚂蚁部落三</td>
    </tr>
    <tr>
      <td>蚂蚁部落一</td>
      <td>蚂蚁部落二</td>
      <td>蚂蚁部落三</td>
    </tr>
    <tr>
      <td>蚂蚁部落一</td>
      <td>蚂蚁部落二</td>
      <td>蚂蚁部落三</td>
    </tr>
    <tr>
      <td>蚂蚁部落一</td>
      <td>蚂蚁部落二</td>
      <td>蚂蚁部落三</td>
    </tr>
    <tr>
      <td>蚂蚁部落一</td>
      <td>蚂蚁部落二</td>
      <td>蚂蚁部落三</td>
    </tr>
  </tbody>
</table>
</body>
</html>

 

以上代码实现了我们的需求,可以让行与行之间隔行变色。

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

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

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助