<!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>
<LINK href="manage.css" rel=stylesheet type=text/css >
<script language="JavaScript" type="text/javascript"><!--
function left_menu(meval)
{
var current=document.getElementById(meval);
if(current.style.display=="none")
{current.style.display="block";}
else
{current.style.display="none";}
}
-->
</SCRIPT>
<base target="right"></head>
<body>
<div class="nav">
<ul>
<li><a onClick="left_menu('left_1');">≡ 公告管理 ≡</a>
<div class="subnav noscreen" id="left_1">
<ul>
<li><a href="3">公告管理</a></li>
</ul>
</div>
</li>
</ul>
</div>
</body>
</html>
请问 第一次单击不运行 第二次就正常了 是什么现象?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<LINK href="manage.css" rel=stylesheet type=text/css >
<script language="JavaScript" type="text/javascript"><!--
function left_menu(meval)
{
var current=document.getElementById(meval);
if(current.style.display=="none")
{current.style.display="block";}
else
{current.style.display="none";}
}
-->
</SCRIPT>
<base target="right"></head>
<body>
<div class="nav">
<ul>
<li><a onClick="left_menu('left_1');">≡ 公告管理 ≡</a>
<div class="subnav noscreen" id="left_1">
<ul>
<li><a href="3">公告管理</a></li>
</ul>
</div>
</li>
</ul>
</div>
</body>
</html>
请问 第一次单击不运行 第二次就正常了 是什么现象?
<div class="subnav noscreen" id="left_1">
<ul>
<li> <a href="3">公告管理 </a> </li>
</ul>
</div>
第二次以后才能正常显示!
程序 本身没有大错 看一下出现什么非技术的问题!
*{
margin:0;
padding:0}
body, div, address, blockquote, iframe, ul, ol, dl, dt, dd,
h1, h2, h3, h4, h5, h6, p, pre, table, caption, th, td,
form, legend, fieldset, input, button, select, textarea {
margin: 0;
padding: 0;
font-weight: normal;
font-style: normal;
font-size: 100%;
font-family: inherit;
}
ol, ul {
list-style: none;
}
fieldset, img {
border: 0;
}
:focus {
outline: 0;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
caption, th {
text-align: left;
}.noscreen {
display: none;
}body {
font-size: 9pt;
color: #000000;
background-color: #CCCCCC;
}
.nav {
text-align: center;
margin: 5px auto;
height: 100%;
width: 80%;
}.nav li {
cursor: hand;
background-color: #00FF00;
border: 1px solid #eeeeee;
font-size: 12pt;
font-weight: bold;
}
.subnav {
background-color: #CCCCCC;
}.subnav li {
font-size: 9pt;
font-weight: normal;
border: 0;
background-color: #FFFFFF;
height: 20px;
width: 100%;
}
if(current.style.display=="block")
{current.style.display="none";}
else
{current.style.display="block";}
<script>left_menu('left_1');</script>
模拟一次单击
<div class="subnav noscreen" id="left_1">
这个未加载出来,当然不会执行。
可以考虑如下方法:<!--
var current=document.getElementById(meval);
function left_menu(meval)
{
if(!current) {
setTimeout(left_menu,200);
}
if(current.style.display=="none")
{current.style.display="block";}
else
{current.style.display="none";}
}
-->
{current.style.display="block";}
else
{current.style.display="none";}
function left_menu(meval)
{
alert(document.getElementById(meval).style.display);
var current=document.getElementById(meval);
if(current.style.display=="none")
{
current.style.display="block";}
else
{current.style.display="none";}
}
第一次document.getElementById(meval).style.display=" ",第二次才等于"none",应该是你定义css的时候出了问题,没有取到它的display值.