html table单双行颜色间隔(转载)

直接上代码:

 1 <html>
 2     <head>
 3         <meta http-equiv="Content-Type" content="text/html; charset=gb3212">
 4         <title>单双行显示不同颜色</title>
 5         <script type="text/javascript">
 6             window.onload = function color(){
 7                 var table = document.getElementById("person");
 8                 var rows = table.getElementsByTagName("tr");
 9                 for(var i=0;i<rows.length;i++){
10                     if (i%2==0){
11                         rows[i].style.backgroundColor = "#EAF2D3"
12                     }else{
13                         rows[i].style.backgroundColor = "White";
14                     }
15                 }
16             }
17         </script>
18         <style type = "text/css">
19             #person
20                 {
21                     border-style:1px solid;
22                     border-color:blue;
23                     font-weight:bold;
24                     font-family:楷体,Arial,Helvetica, sans-serif;
25                     border-collapse:collapse;
26                     margin:auto;
27                 }
28             #person th
29                 {
30                     border:1px solid;
31                     padding:3px 7px 2px 7px
32                     background-color:#A7C942
33                     color:#ffffff
34                     text-align:center;
35                 }
36             #person td
37                 {
38                     border-style:solid;
39                     border-width:1px;
40                     text-align:center;
41                 }
42         </style>
43     </head>
44     <body>
45         <table id="person" align="center" width = "90%" height="200">
46             <tr>
47                 <th>姓名</th>
48                 <th>性别</th>
49                 <th>电话</th>
50                 <th>爱好</th>
51             </tr>
52             <tr>
53                 <td>zhangsan</td>
54                 <td>male</td>
55                 <td>123456</td>
56                 <td>swimming</td>
57             </tr>
58             <tr>
59                 <td>zhangsan</td>
60                 <td>male</td>
61                 <td>123456</td>
62                 <td>swimming</td>
63             </tr>
64             <tr>
65                 <td>zhangsan</td>
66                 <td>male</td>
67                 <td>123456</td>
68                 <td>swimming</td>
69             </tr>
70         </table>
71     </body>
72 </html>
时间: 2024-08-10 16:58:29

html table单双行颜色间隔(转载)的相关文章

js改变,设置table单双行颜色,jquery改变,设置table单双行颜色

1.js实现单双行以不同颜色显示 $(document).ready(function () { var color = "#ffeab3"; $("#GvList tr:odd td").css("background-color", color); //改变偶数行背景色 $("#GvList tr:odd").attr("bg", color); $("#GvList tr:even"

table 控制单双行颜色以及鼠标hover颜色 table光棒

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="

设置表格单双行颜色

<script type="text/javascript"> $(document).ready(function () { $("table").attr("bgColor", "#222222"); //设置表格的背景颜色 $("tr").attr("bgColor", "#3366CC"); //为单数行表格设置背景颜色 $("tr:ev

Js实现table单双行交替色

依稀记得,当初我刚学编程的时候还学过怎么实现表格单双行交替色,现如今早已记不清当时的实现思路,这两天突然想起,没事就自己写了一小段代码,也不知道是否是当年的思路,不过不用纠结这个问题.:) 代码很简单,利用纯Js实现表格单双行交替色. //Js实现表格单双行交替色 function SetTrColor(tableId) { var table = document.getElementById(tableId);//根据table的 id 属性值获得对象 var rows = table.ge

示例-行颜色间隔显示并高亮

<link rel="stylesheet" type="text/css" href="css.css" /> <style type="text/css"> .one{ background-color:#e1e16a; } .two{ background-color:#75f094; } .over{ background-color:#0F6; } </style> <scr

JS实战 &#183; 表格行颜色间隔显示,并在鼠标指定行上高亮显示

思路: 1.获取所有行对象,将需要间隔颜色显示的行对象进行动态的className属性指定: 前提是:先定义好类选择器,就是说给行对象赋予name. 2.高亮用到两个事件:onmouseover(鼠标进入事件).onmouseout(鼠标移 出事件) 3.为了方便可以在遍历行对象时将每一个行对象都进行两个事件属性的制度,并通 过匿名函数完成该事件的处理: 4.高亮的原理:将鼠标进入时颜色改变,改变前先记录下原行对象的样式,在鼠标 离开时,将该样式还原: 5.改样式需要在页面加载完成后直接显示,所

Gridview单双行

.table01_singlar        {            background-color: #FFFFFF;        }.table01_double        {            background-color: #e5eaf0;        } OnRowDataBound="gvData_RowDataBound" protected void gvData_RowDataBound(object sender, GridViewRowEve

css单双行样式

#random_box li:nth-child(odd) {//双行 background: #fff5c4; } #random_box li:nth-child(even) {//单行 background: #ffeb8c; }

隔行变色以及单双行变色,鼠标一入一出变色

1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script type = "text/javascript" src = "js/jquery/easyui-1.3.0/jquery-1.7.2.min.js"></script> 5 <script type = "text/javascript"> 6 $(document).ready(f