jquery 雙色表格實現(xiàn)代碼
更新時間:2009年12月08日 00:45:23 作者:
上次用javascript實現(xiàn)了上色表格,見<JS實現(xiàn)雙色表格>。但通過jQuery強大的選擇器可更加簡潔,優(yōu)雅的實現(xiàn)。
http://www.dhdzp.com/article/21027.htm
不多說了,直接給代碼
代碼
<html>
<head>
<title>雙色表格</title>
<style type="text/css">
<!--
table {
border:solid 1px black;
text-align:center;
border-spacing:0px;
}
th,td {
border:solid 1px black;
width:100px;
}
-->
</style>
<script src="lib/jquery.js" type="text/javascript"></script>
<script type="text/javascript" >
$().ready(function() {
$('tr:has(th)').css('background','violet'); //表格標題
$('tr:even:gt(0)').css('background','yellow'); //偶數(shù)行,且行數(shù)大于0(即標題)
$('tr:odd').css('background','olive'); //奇數(shù)行
});
</script>
</head>
<body>
<center>
<table>
<tr id="th">
<th>姓名</th>
<th>科目</th>
<th>成績</th>
</tr>
<tr>
<td>張三</td>
<td>語文</td>
<td>90</td>
</tr>
<tr>
<td>張三</td>
<td>數(shù)學</td>
<td>87</td>
</tr>
<tr>
<td>李四</td>
<td>數(shù)學</td>
<td>68</td>
</tr>
<tr>
<td>王五</td>
<td>英語</td>
<td>76</td>
</tr>
</table>
</center>
</body>
</html>
不多說了,直接給代碼
代碼
復制代碼 代碼如下:
<html>
<head>
<title>雙色表格</title>
<style type="text/css">
<!--
table {
border:solid 1px black;
text-align:center;
border-spacing:0px;
}
th,td {
border:solid 1px black;
width:100px;
}
-->
</style>
<script src="lib/jquery.js" type="text/javascript"></script>
<script type="text/javascript" >
$().ready(function() {
$('tr:has(th)').css('background','violet'); //表格標題
$('tr:even:gt(0)').css('background','yellow'); //偶數(shù)行,且行數(shù)大于0(即標題)
$('tr:odd').css('background','olive'); //奇數(shù)行
});
</script>
</head>
<body>
<center>
<table>
<tr id="th">
<th>姓名</th>
<th>科目</th>
<th>成績</th>
</tr>
<tr>
<td>張三</td>
<td>語文</td>
<td>90</td>
</tr>
<tr>
<td>張三</td>
<td>數(shù)學</td>
<td>87</td>
</tr>
<tr>
<td>李四</td>
<td>數(shù)學</td>
<td>68</td>
</tr>
<tr>
<td>王五</td>
<td>英語</td>
<td>76</td>
</tr>
</table>
</center>
</body>
</html>
您可能感興趣的文章:
相關(guān)文章
jQuery插件simplePagination的使用方法示例
這篇文章主要介紹了jQuery插件simplePagination的使用方法,結(jié)合實例形式分析了jQuery插件simplePagination實現(xiàn)表單分頁相關(guān)操作技巧與注意事項,需要的朋友可以參考下2020-04-04
jQuery 順便學習下CSS選擇器 奇偶匹配nth-child(even)
今天學習jQuery,看到nth-child(even)用法,特意找了下這個選擇器的用法,在CSS3標準中,用法很強大。2010-05-05

