jQuery实现的table表格隔行换色代码实例

jQuery实现的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;
}
.even{background:#FFF38F;}
.odd{background:#FFFFEE;}
.selected{background:#FF9900;}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
  $("#thetable tr:odd").addClass("odd");
  $("#thetable tr:even").addClass("even");
});
</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.addClass()函数可以参阅jQuery的addClass()方法一章节。

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

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

时间: 2024-08-03 03:14:29

jQuery实现的table表格隔行换色代码实例的相关文章

jQuery应用实例2:表格隔行换色

这里是用JS实现的:http://www.cnblogs.com/xuyiqing/p/8376312.html 接下来利用上一篇提到的选择器利用jQuery实现: 发现原来多行代码这里只需要两行: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>表格隔行换色</title> <script type="text/javascr

JQuery案例一:实现表格隔行换色

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>使用JQ完成表格隔行换色</title> <script src="js/jquery.min.js"></script> <script> $(function() { $("tbody tr:odd").css(&qu

jQuery实现表格隔行换色且感应鼠标高亮行变色

jQuery插件实现表格隔行换色且感应鼠标高亮行变色 http://www.jb51.net/article/41568.htm jquery 操作DOM的基本用法分享http://www.jb51.net/article/30047.htm jQuery技术之事件处理 http://blog.csdn.net/woshisap/article/details/7434010 jQuery实现表格隔行换色且感应鼠标高亮行变色,布布扣,bubuko.com

表格隔行换色及删除后仍隔行换色效果(好别扭的标题。。。)

表格隔行换色,有多种写法,可以通过jquery来写,也可以用css3实现. 1.jquery方法 odd,奇数:even,偶数 方法很简单 $("tr:odd").css({background:"#c66",color:"#fff"}); $('tr:even').css({background:"#fff",color:"#333"}); 但是如果删除后,两个一样背景的tr会挨上,怎么解决呢?可以将换行

三种php表格隔行换色

第一种for{}eles{}: <?php echo "<table width='80%' border = 1 cellpadding=5 cellspacing=0>"; for ($i = 1; $i <= 5; $i++){ if($i % 2 == 0){ echo '<tr align="center" bgcolor="red">'; }else{ echo '<tr align=&quo

表格隔行换色

实现列表中隔行显示背景颜色 Html代码 <div class="searchListDetail"> <ul class="bold"> <li>姓名</li><li>公司</li><li>职位</li><li>标签</li><li>性别</li><li>工作年限</li> </ul>

js表格隔行换色和hover效果

<!--js效果--> <script src="js/jquery.min.js" language="javascript"></script> <script> $(document).ready(function(){///////datagrid选中行变色与鼠标经过行变色///////////////var dtSelector = ".list";var tbList = $(dtSel

表格 隔行换色

1.原生JS实现 1 <script type="text/javascript"> 2 var oTable = document.getElementById("table"); 3 var oTr = oTable.getElementsByTagName("tr"); 4 for (var i=0; i<oTr.length;i++) 5 { 6 if (i%2) 7 oTr[i].style.background =

JQ表格隔行换色

<style type="text/css"> html, body { margin: 0; padding: 0; font-size: 15px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; } ul { list-style: none; border: 1px solid #5bc0de; width: 600px; margin: 0 auto; padding: