首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > 高性能WEB开发 >

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

2013-01-08 
js代码提示脚本有误,高手帮忙修改下!!!!运行js脚本提示style为空或不是对象,js脚本如下,请帮忙修改下:scr

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"


          }
      }
      li[i].onmouseover=function(){
         this.style.backgroundColor="#beeeff";
      };
  }
[解决办法]

  for (var i=0;i<=li.length;i++){

红色部分去掉。。。。
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
运行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>
</body>
</html>

热点排行