<body>
<table id="table_s" width="98%" border="1" cellspacing="2" cellpadding="2">
  <tr>
    <td>高峰时段分萨菲都是</td>
    <td>是高手 </td>
  </tr>
  <tr>
    <td>撒古斯个萨格 </td>
    <td>阿三哥隔热个人 </td>
  </tr>
    <tr>
    <td>撒古斯个萨格 </td>
    <td>阿三哥隔热个人 </td>
  </tr>
</table><script type="text/javascript"> 
var tbl = document.getElementById("table_s"); 
for(var i=0;i <tbl.rows.length;i++){ 
  if(i%2 == 0) tbl.rows[i].style.backgroundColor ="#996633"; 
  else tbl.rows[i].style.backgroundColor = "#FF0000"; 

</script>
</body>

解决方案 »

  1.   

    代码是从上往下跑的,所以你要把js放html下面,因为你的js中有用到html元素,先把这个调正,然后再试一下!
      

  2.   

    不需要设置js的位置,换种思维写javascript吧,我修改后的版本,在ie7及Firefox下测试通过:<body><script type="text/javascript"> window.onload = function(){
    var oTable = document.getElementById("table_s");
    for(var i=0;i<oTable.rows.length;i++){
    if(i%2==0) //偶数行时
    oTable.rows[i].style.backgroundColor = "#996633";
    else
    oTable.rows[i].style.backgroundColor = "#FF0000";
    }
    }
    </script><table id="table_s" width="98%" border="1" cellspacing="2" cellpadding="2">
      <tr>
        <td>高峰时段分萨菲都是</td>
        <td>是高手 </td>
      </tr>
      <tr>
        <td>撒古斯个萨格 </td>
        <td>阿三哥隔热个人 </td>
      </tr>
        <tr>
        <td>撒古斯个萨格 </td>
        <td>阿三哥隔热个人 </td>
      </tr>
    </table></body>