<div class="codetitle"> <span><a style="CURSOR: pointer" data="4253" class="copybut" id="copybut4253" onclick="doCopy('code4253')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code4253"> <br><style type="text/css"> <BR>body {body <BR>font-size:12px;text-align:center; <BR>} <BR>#tbStu { <BR>width:260px;border:1px solid #666;background-color:#eee <BR>}; <BR>#tbStu tr { <BR>line-height:23px; <BR>} <BR>#tbStu tr th { <BR>background-color:#ccc;color:#fff; <BR>} <BR> #tbStu .trOdd { <BR>background-color:#fff; <BR>} <BR></style> <br><script src="jQuery/jquery-1.9.1.js"></script> <br><script type="text/javascript"> <BR>// var oTb = document.getElementById('tbStu'); <BR>// for (var i = 0; i < oTb.rows.length-1; i ) { <BR>// if (i % 2) <BR>// { <BR>// oTb.rows [i].className = "trOdd"; <BR>// } <BR>// } <BR>//} <BR>//jQuery選擇器寫法(選取table的行,隔一行,選取一行) <BR>$(function () { <BR>$('#tbStu tr:nth-child(even)').addClass("trOdd"); <BR>//jQuery複製內容時,不需要偵測該DIV是否存在<BR>// $('#divMain').html('這是一個檢測頁面'); <BR>}) <BR></script> <br> <br> <br><table id="tbStu" cellpadding="0" cellspacing="0"> <br><tbody> <br><tr> <br><th>學號</th> <th>姓名</th> <th>性別</th> <th>部分</th> <br> </tr> <br><tr> <br><td>1001</td> <td>張小明</td> <td>男</td> <td>320</td> <br> </tr> <br><tr> <br><td>1002</td> <td>李明琪 td></td> <td>女</td> <td>350</td> <br> </tr> <br><tr> <br><td>1003</td> <td>張三</td> <td>男</td> <td>150</td> <br> </tr> <br> </tbody> <br> </table> <br> <br><br> </div>