<div class="htmlarea"> <textarea id="runcode48424"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>table 隔列换色效果</title> <style> #test{ background-color:#C96; text-align:center; line-height:2em;} .over{background-color:#fff;} .out{background-color:#F1F1F1;} </style> <script> window.onload = function(){ //returnColor("test"); setColor("test"); } function setColor(id) { var trs=document.getElementById(id).getElementsByTagName("tr"); for(var i=0; i<trs.length; i++) { var tds = trs[i].getElementsByTagName("td"); for(var j=0; j<tds.length; j++) { if(j%2==1) { tds[j].className="over"; } else { tds[j].className="out"; } } } } </script> <table width="50%" border="0" cellspacing="1" cellpadding="0" id="test"> <tr> <td>0 </td> <td>1 </td> <td>2 </td> <td>18</td> </tr> <tr> <td>3 </td> <td>4 </td> <td>5 </td> <td>19</td> </tr> <tr> <td>6 </td> <td>7 </td> <td>8 </td> <td>20</td> </tr> <tr> <td>9</td> <td>10</td> <td>11</td> <td>21</td> </tr> <tr> <td>12</td> <td>13</td> <td>14</td> <td>22</td> </tr> <tr> <td>15</td> <td>16</td> <td>17</td> <td>23</td> </tr> <tr> <td>27</td> <td>26</td> <td>25</td> <td>24</td> </tr> </table> </textarea><br><input onclick="runEx('runcode48424')" type="button" value="运行代码"> <input onclick="doCopy('runcode48424')" type="button" value="复制代码"> <input onclick="doSave(runcode48424)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>