表格隔行变色
静态下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style type="text/css">
table{
background-color:#fff;
color:#565;
font:12px Arial, Helvetica, sans-serif;
text-align:left;
border:none;
}
table caption{
font-size:24px;
border-bottom:2px solid #B3DE94;
border-top:2px solid #B3DE94;
}
table,td,th{
margin:0;
padding:0;
vertical-align:middle;
}
tbody td,tbody th{
background-color:#dfc;
padding:9px;
border-bottom:2px solid #B3DE94;
border-top:3px solid #ffffff;
}
tfoot td,tfoot th{
text-align:center;
margin:4px 8px 6px 9px;
font-weight:bold;
}
thead th{
font-size:14px;
line-height:19px;
text-align:center;
padding:0 8px 2px;
}
tbody tr.even th,tbody tr.even td{
background-color:#cea;
border-bottom:2px solid #67bd2a;
}
col.price{
text-align:right;
}
</style>
<body>
<table summary="book list">
<caption>Book List</caption>
<col /><col /><col /><col class="price" /><col />
<thead>
<tr>
<th>Title</th>
<th>ID</th>
<th>Country</th>
<th>Price</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<tr>
<th>Tom</th>
<td>123456</td>
<td>Germany</td>
<td>$3.12</td>
<td>Download</td>
</tr>
<tr class="even">
<th>Aom</th>
<td>123456</td>
<td>Germany</td>
<td>$3.12</td>
<td>Download</td>
</tr>
<tr>
<th>Tina</th>
<td>123456</td>
<td>Germany</td>
<td>$3.12</td>
<td>Download</td>
</tr>
<tr class="even">
<th>Os</th>
<td>123456</td>
<td>Germany</td>
<td>$3.12</td>
<td>Download</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Total</th>
<td colspan="4">4 books</td>
</tr>
</tfoot>
</table>
</body>
</html>
鼠标点击
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<style type="text/css">
table{
color:#565;
font:12px Arial, Helvetica, sans-serif;
}
td{
padding:9px;
border-bottom:2px solid #B3DE94;
border-top:3px solid #ffffff;
}
tr{
background-color:#dfc;
}
tr:hover,tr.hover{
background-color:#595;
color:#fff;
}
</style>
<body>
<table summary="book list">
<caption>Book List</caption>
<tr>
<td>Title</td>
<td>ID</td>
<td>Country</td>
<td>Price</td>
<td>Download</td>
</tr>
<tr>
<td>Tom</td>
<td>123456</td>
<td>Germany</td>
<td>$3.12</td>
<td>Download</td>
</tr>
<tr>
<td>Aom</td>
<td>123456</td>
<td>Germany</td>
<td>$3.12</td>
<td>Download</td>
</tr>
<tr>
<td>Tina</td>
<td>123456</td>
<td>Germany</td>
<td>$3.12</td>
<td>Download</td>
</tr>
<tr>
<td>Os</td>
<td>123456</td>
<td>Germany</td>
<td>$3.12</td>
<td>Download</td>
</tr>
</table>
<script language="javascript">
var rows=document.getElementsByTagName('tr');//rows是一个行的数组,包含当前页中所有的行
for(var i=0;i<rows.length;i++)
{
rows[i].onmouseover=function()
{
this.className='hover';
}
rows[i].onmouseout=function()
{
this.className='';
}
}
</script>
</body>
</html>