<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EW""http://www.w3.org/TR/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><!--插入腳本 載入jquery-1.4.2.min.js文件 結(jié)束腳本--><script language="javascript" type="text/javascript" src="jquery-1.4.2.min.js"></script><!--定義樣式--><style type="text/css"><!--定義 body身體的尺寸 tbStu大小 和顏色 tbSut tr-->body{font-size:12px;text-align:center}#tbStu{width:260px;border:soild 1px #666;background-color:#eee}#tbSut tr{line-heiht:23px}#tbSut tr th{background-color:#ccc;color:#fff}#tbSut .trOdd{background-color:#fff}
<!--結(jié)束定義樣式--></style><!--腳本插入--><script type="text/javascript"><!--創(chuàng)建函數(shù)-->$(function()
{ <!--查詢到tbStu tr nth-child(even) 分別匹配序號(hào)為奇數(shù)與偶數(shù)的元素 增加trOdd 設(shè)置顏色-->
$("#tbStu tr:odd").addClass("trOdd");
})<!--結(jié)束腳本插入--></script></head><body><table id="tbStu" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th>學(xué)號(hào)</th><th>姓名</th><th>性別</th><th>總分</th>
</tr>
<tr>
<td>1001</td><td>張小明</td><td>男</td><td>320</td>
</tr>
<tr>
<td>1002</td><td>李明琪</td><td>女</td><td>350</td>
</tr>
</tbody></table></body></html>為什么改變不了?tbSut tr th{background-color:#ccc;color:#fff}tbSut .trOdd{background-color:#fff}
1 回答

慕妹3242003
TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
TR 標(biāo)簽?zāi)芗宇伾膯??汗?br/>把這個(gè)#tbSut .trOdd{background-color:#fff}
改成:#tbSut .trOdd td{background-color:#fff}
又或者
$("tr:nth-child(odd)").css("background","#fff");
- 1 回答
- 0 關(guān)注
- 220 瀏覽
添加回答
舉報(bào)
0/150
提交
取消