js提示缺少对象,代码贴出来了,求解
<scriptlanguage="javascript">functionqiehuan(num){for(varid=0;id<=9;id++){if(id==num)...
<script language="javascript">
function qiehuan(num){
for(var id = 0;id<=9;id++)
{
if(id==num)
{
document.getElementById("qh_con"+id).style.display="block";
document.getElementById("mynav"+id).className="nav_on";
}
else
{
document.getElementById("qh_con"+id).style.display="none";
document.getElementById("mynav"+id).className="";
}
}
}
</script>
<div class="menu">
<ul>
<li class="first"><a href="#" onmouseover="javascript:qiehuan(0)" id="mynav0" class="nav_on">首 页</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(1)" id="mynav1" class="nav_off">酷站代码</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(2)" id="mynav2" class="nav_off">网页特效</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(3)" id="mynav3" class="nav_off">网页教程</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(4)" id="mynav4" class="nav_off">建站教程</a></li>
<li class="last"><a href="#" onmouseover="javascript:qiehuan(5)" id="mynav5" class="nav_off">建站教程</a></li>
</ul>
</div>
<div class="ft">
<div id="qh_con0" style="display:block">
<a href="#">栏目名称1</a>
<a href="#">栏目名称2</a>
<a href="#">栏目名称3</a>
</div>
<div id="qh_con1" style="display:none">
<a href="#">栏目名称4</a>
<a href="#">栏目名称5</a>
<a href="#">栏目名称6</a>
</div>
<div id="qh_con2" style="display:none">
<a href="#">栏目名称7</span></a>
<a href="#">栏目名称8</span></a>
<a href="#">栏目名称9</span></a>
</div>
<div id="qh_con3" style="display:none">
<a href="#">栏目名称10</a>
<a href="#">栏目名称11</a>
<a href="#">栏目名称12</a>
</div>
<div id="qh_con4" style="display:none">
<a href="#">栏目名称13</a>
<a href="#">栏目名称14</a>
<a href="#">栏目名称15</a>
</div>
<div id="qh_con5" style="display:none">
<a href="#">栏目名称16</a>
<a href="#">栏目名称17</a>
<a href="#">栏目名称18</a>
</div>
</div>
IE提示12行字符17缺少对象求解,不知道哪里有错误啊 展开
function qiehuan(num){
for(var id = 0;id<=9;id++)
{
if(id==num)
{
document.getElementById("qh_con"+id).style.display="block";
document.getElementById("mynav"+id).className="nav_on";
}
else
{
document.getElementById("qh_con"+id).style.display="none";
document.getElementById("mynav"+id).className="";
}
}
}
</script>
<div class="menu">
<ul>
<li class="first"><a href="#" onmouseover="javascript:qiehuan(0)" id="mynav0" class="nav_on">首 页</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(1)" id="mynav1" class="nav_off">酷站代码</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(2)" id="mynav2" class="nav_off">网页特效</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(3)" id="mynav3" class="nav_off">网页教程</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(4)" id="mynav4" class="nav_off">建站教程</a></li>
<li class="last"><a href="#" onmouseover="javascript:qiehuan(5)" id="mynav5" class="nav_off">建站教程</a></li>
</ul>
</div>
<div class="ft">
<div id="qh_con0" style="display:block">
<a href="#">栏目名称1</a>
<a href="#">栏目名称2</a>
<a href="#">栏目名称3</a>
</div>
<div id="qh_con1" style="display:none">
<a href="#">栏目名称4</a>
<a href="#">栏目名称5</a>
<a href="#">栏目名称6</a>
</div>
<div id="qh_con2" style="display:none">
<a href="#">栏目名称7</span></a>
<a href="#">栏目名称8</span></a>
<a href="#">栏目名称9</span></a>
</div>
<div id="qh_con3" style="display:none">
<a href="#">栏目名称10</a>
<a href="#">栏目名称11</a>
<a href="#">栏目名称12</a>
</div>
<div id="qh_con4" style="display:none">
<a href="#">栏目名称13</a>
<a href="#">栏目名称14</a>
<a href="#">栏目名称15</a>
</div>
<div id="qh_con5" style="display:none">
<a href="#">栏目名称16</a>
<a href="#">栏目名称17</a>
<a href="#">栏目名称18</a>
</div>
</div>
IE提示12行字符17缺少对象求解,不知道哪里有错误啊 展开
1个回答
展开全部
这段代码 我在IE9 firefox14 chrome 下都测了 没问题 是不是 你的其他代码有问题
<html>
<head>
</head>
<body>
<script language="javascript">
function qiehuan(num){
for(var id = 0;id<=9;id++)
{
if(id==num)
{
document.getElementById("qh_con"+id).style.display="block";
document.getElementById("mynav"+id).className="nav_on";
}
else
{
document.getElementById("qh_con"+id).style.display="none";
document.getElementById("mynav"+id).className="";
}
}
}
</script>
<div class="menu">
<ul>
<li class="first"><a href="#" onmouseover="javascript:qiehuan(0)" id="mynav0" class="nav_on">首 页</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(1)" id="mynav1" class="nav_off">酷站代码</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(2)" id="mynav2" class="nav_off">网页特效</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(3)" id="mynav3" class="nav_off">网页教程</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(4)" id="mynav4" class="nav_off">建站教程</a></li>
<li class="last"><a href="#" onmouseover="javascript:qiehuan(5)" id="mynav5" class="nav_off">建站教程</a></li>
</ul>
</div>
<div class="ft">
<div id="qh_con0" style="display:block">
<a href="#">栏目名称1</a>
<a href="#">栏目名称2</a>
<a href="#">栏目名称3</a>
</div>
<div id="qh_con1" style="display:none">
<a href="#">栏目名称4</a>
<a href="#">栏目名称5</a>
<a href="#">栏目名称6</a>
</div>
<div id="qh_con2" style="display:none">
<a href="#">栏目名称7</span></a>
<a href="#">栏目名称8</span></a>
<a href="#">栏目名称9</span></a>
</div>
<div id="qh_con3" style="display:none">
<a href="#">栏目名称10</a>
<a href="#">栏目名称11</a>
<a href="#">栏目名称12</a>
</div>
<div id="qh_con4" style="display:none">
<a href="#">栏目名称13</a>
<a href="#">栏目名称14</a>
<a href="#">栏目名称15</a>
</div>
<div id="qh_con5" style="display:none">
<a href="#">栏目名称16</a>
<a href="#">栏目名称17</a>
<a href="#">栏目名称18</a>
</div>
</div>
</body>
</html>
<html>
<head>
</head>
<body>
<script language="javascript">
function qiehuan(num){
for(var id = 0;id<=9;id++)
{
if(id==num)
{
document.getElementById("qh_con"+id).style.display="block";
document.getElementById("mynav"+id).className="nav_on";
}
else
{
document.getElementById("qh_con"+id).style.display="none";
document.getElementById("mynav"+id).className="";
}
}
}
</script>
<div class="menu">
<ul>
<li class="first"><a href="#" onmouseover="javascript:qiehuan(0)" id="mynav0" class="nav_on">首 页</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(1)" id="mynav1" class="nav_off">酷站代码</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(2)" id="mynav2" class="nav_off">网页特效</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(3)" id="mynav3" class="nav_off">网页教程</a></li>
<li><a href="#" onmouseover="javascript:qiehuan(4)" id="mynav4" class="nav_off">建站教程</a></li>
<li class="last"><a href="#" onmouseover="javascript:qiehuan(5)" id="mynav5" class="nav_off">建站教程</a></li>
</ul>
</div>
<div class="ft">
<div id="qh_con0" style="display:block">
<a href="#">栏目名称1</a>
<a href="#">栏目名称2</a>
<a href="#">栏目名称3</a>
</div>
<div id="qh_con1" style="display:none">
<a href="#">栏目名称4</a>
<a href="#">栏目名称5</a>
<a href="#">栏目名称6</a>
</div>
<div id="qh_con2" style="display:none">
<a href="#">栏目名称7</span></a>
<a href="#">栏目名称8</span></a>
<a href="#">栏目名称9</span></a>
</div>
<div id="qh_con3" style="display:none">
<a href="#">栏目名称10</a>
<a href="#">栏目名称11</a>
<a href="#">栏目名称12</a>
</div>
<div id="qh_con4" style="display:none">
<a href="#">栏目名称13</a>
<a href="#">栏目名称14</a>
<a href="#">栏目名称15</a>
</div>
<div id="qh_con5" style="display:none">
<a href="#">栏目名称16</a>
<a href="#">栏目名称17</a>
<a href="#">栏目名称18</a>
</div>
</div>
</body>
</html>
更多追问追答
追问
你好 IE6提示缺少对象,目前使用IE6的人还是很多,所以怕以后出什么问题
追答
IE6是垃圾 对DIV的兼容性非常差
else
{
document.getElementById("qh_con"+id).style.display="none";
document.getElementById("mynav"+id).className="nav_off";
}
这个classname为空改成nav_off试一下
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询