日期:2014-05-17 浏览次数:20682 次
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style> #hongse{ background-color:#333;} .baise{ background-color:#FFF;} .huangse{background:#CC0;} </style> <script language="javascript" src="javascript/jquery.min.js"></script> <script language="javascript"> $( function() { $("table tr:nth-child(odd)").addClass("huangse"); } ); </script> </head> <body> <table width="500" border="0" cellpadding="0" cellspacing="1" id="hongse"> <tr class="baise"> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> </tr> <tr class="baise"> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> </tr> <tr class="baise"> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> <td height="28" align="center" valign="middle">jquery隔行换色测试</td> </tr> </table> </body> </html>
------解决方案--------------------
$('.tab tr:odd td').css({background:'奇数行背景色',color:'#奇数行前景色'});
$('.tb tr:even td').css({background:'偶数行背景色',color:'偶数行前景色'});