运行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%"> </td>
</tr>
<tr>
<td >个人简介</td>
<td> </td>
</tr>
<tr>
<td >联系电话</td>
<td> </td>
</tr>
<tr>
<td > </td>
<td> </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"