当前位置: 代码迷 >> 高性能WEB开发 >> js代码提示脚本有误,高手帮忙修改上!
  详细解决方案

js代码提示脚本有误,高手帮忙修改上!

热度:117   发布时间:2013-01-08 14:02:13.0
js代码提示脚本有误,高手帮忙修改下!!!!
运行js脚本提示style为空或不是对象,js脚本如下,请帮忙修改下:
<script language="javascript">
window.onload=function showtable(){
   var tablename=document.getElementById("mytable");
   var li=tablename.getElementsByTagName("tr");
   for (var i=0;i<=li.length;i++){
    if(i%2==0){
     li[i].style.backgroundColor="#F3F8F7";
     li[i].onmouseout=function(){
         this.style.backgroundColor="#F3F8F7"
      }
    }else{
     li[i].style.backgroundColor="#fff";
     li[i].onmouseout=function(){
         this.style.backgroundColor="#fff"
      }
    }
      li[i].onmouseover=function(){
      this.style.backgroundColor="#beeeff";
      }
   }
}
</script>

 <table id="mytable" width="99%" border="0" align="center"  cellpadding="3" cellspacing="1">
    <tr>
      <td width="18%上传个人照片</td>
      <td width="82%">&nbsp;</td>
    </tr>
    <tr>
      <td >个人简介</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td >联系电话</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td >&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
</table>

------解决方案--------------------
for (var i=0;i<=li.length-1;i++){
}

-1下 。
下标越界了 。
------解决方案--------------------
<td width="18%">上传个人照片</td>

这个标签没闭合 。
------解决方案--------------------
for (var i=0;i<=li.length;i++){
改为
for (var i=0;i<li.length;i++){


<td width="18%">上传个人照片</td>

这个标签没闭合 
------解决方案--------------------
 var tablename=document.getElementById("mytable");
  var li=tablename.rows;
  for (var i=0;i<li.length;i++)
  {
      if(i%2==0){
          li[i].style.backgroundColor="#F3F8F7";
          li[i].onmouseout=function(){
          this.style.backgroundColor="#F3F8F7"
          }
      }else{
         li[i].style.backgroundColor="#fff";
          li[i].onmouseout=function(){
          this.style.backgroundColor="#fff"
  相关解决方案