网页错误document.getElementById(...)为空或不是对象,帮忙看下代码
打开网页出现错误:document.getElementById(...)为空或不是对象。帮忙看下问题在哪?如何更正(正在学习,请具体点)。谢!代码如下:<html><b...
打开网页出现错误:document.getElementById(...)为空或不是对象。帮忙看下问题在哪?如何更正(正在学习,请具体点)。谢!
代码如下:
<html>
<body>
<div class="commend mt1 topshang">
<ul class="indexright">
<li onmouseover="shownews('news1')" id="news1">
<h3>标题一</h3>
<ul class="indexrlist">
<li><a href="#" target="_blank">项目一</a></li>
<li><a href="#" target="_blank">项目二</a></li>
</ul>
</li>
<li class="indexrtit" onmouseover="shownews('news2')" id="news2">
<h3>标题二</h3>
<ul class="indexrlist">
<li><a href="#" target="_blank">项目一</a></li>
<li><a href="#" target="_blank">项目二</a></li>
</ul>
</li>
<li class="indexrtit" onmouseover="shownews('news3')" id="news3">
<h3>标题三</h3>
<ul class="indexrlist">
<li><a href="#" target="_blank">项目一</a></li>
<li><a href="#" target="_blank">项目二</a></li>
</ul>
</li>
<li class="indexrtit" onmouseover="shownews('news4')" id="news4">
<h3>标题四</h3>
<ul class="indexrlist">
<li><a href="#" target="_blank">项目一</a></li>
<li><a href="#" target="_blank">项目二</a></li>
</ul>
</li>
<li class="indexrtit"><h3><a href="#" target="_blank">更多...</a></h3>
</li>
</ul>
</div>
</body>
<script>
var news = [];
news = ['news1','news2','news3','news4'];
function shownews(id)
{
document.getElementById(id).className = '';
for(var i=0;i<news.length+1;i++)
{
if(id!= news[i])
{
document.getElementById(news[i]).className = 'indexrtit';
}
}
}
</script>
</html> 展开
代码如下:
<html>
<body>
<div class="commend mt1 topshang">
<ul class="indexright">
<li onmouseover="shownews('news1')" id="news1">
<h3>标题一</h3>
<ul class="indexrlist">
<li><a href="#" target="_blank">项目一</a></li>
<li><a href="#" target="_blank">项目二</a></li>
</ul>
</li>
<li class="indexrtit" onmouseover="shownews('news2')" id="news2">
<h3>标题二</h3>
<ul class="indexrlist">
<li><a href="#" target="_blank">项目一</a></li>
<li><a href="#" target="_blank">项目二</a></li>
</ul>
</li>
<li class="indexrtit" onmouseover="shownews('news3')" id="news3">
<h3>标题三</h3>
<ul class="indexrlist">
<li><a href="#" target="_blank">项目一</a></li>
<li><a href="#" target="_blank">项目二</a></li>
</ul>
</li>
<li class="indexrtit" onmouseover="shownews('news4')" id="news4">
<h3>标题四</h3>
<ul class="indexrlist">
<li><a href="#" target="_blank">项目一</a></li>
<li><a href="#" target="_blank">项目二</a></li>
</ul>
</li>
<li class="indexrtit"><h3><a href="#" target="_blank">更多...</a></h3>
</li>
</ul>
</div>
</body>
<script>
var news = [];
news = ['news1','news2','news3','news4'];
function shownews(id)
{
document.getElementById(id).className = '';
for(var i=0;i<news.length+1;i++)
{
if(id!= news[i])
{
document.getElementById(news[i]).className = 'indexrtit';
}
}
}
</script>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询