jquery實現奇偶行賦值不同css值

來源:互聯網
上載者:User

效果如下:


使用jquery我們可以輕鬆的實現上面效果,代碼如下:

複製代碼 代碼如下:<html>
<head>
<title>jquery奇偶行css效果</title>
<script src="http://img.jb51.net/jslib/jquery/jquery.js" type="text/javascript"></script>
<style type="text/css">
/*table中偶數行*/
.tabEven
{
background: #9d8e8b;
}
/*table中奇數行*/
.tabOdd
{
background: #ffffff;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
$("#datalist tr:even").addClass("tabEven");
$("#datalist tr:odd").addClass("tabOdd");
});
</script>
</head>
<body>
<table id="datalist">
<tr><td>第1行</td></tr>
<tr><td>第2行</td></tr>
<tr><td>第3行</td></tr>
<tr><td>第4行</td></tr>
<tr><td>第5行</td></tr>
</table>
</body>
</html>
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.