目标是:点击一级菜单“one”时,显示二级菜单“one.1,one.2,....”
代码如下:<!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" xml:lang="en" lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="www.budingwang.com" /> <title>无标题 1</title>
<style>
*{margin:0px;padding:0px;}
li{list-style: none;}
li > ul{display:none;}
</style>
</head>
<body>
<ul id="tree">
<li>
<a id="first" href="#">one</a>
<ul id="first_child">
<li>one.1</li>
<li>one.2</li>
</ul>
</li>
</ul>
</body>
<script>
document.getElementById("first").addEventListener("click",nodeAction,false);
function nodeAction(){
if(document.getElementById("first_child").style.display=="block"){ //这里为none时,前两次点击有效,之后无效,搞不懂???
document.getElementById("first_child").style.display="none";
}else{
document.getElementById("first_child").style.display="block";
}
}
</script>
</html>
代码如下:<!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" xml:lang="en" lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="www.budingwang.com" /> <title>无标题 1</title>
<style>
*{margin:0px;padding:0px;}
li{list-style: none;}
li > ul{display:none;}
</style>
</head>
<body>
<ul id="tree">
<li>
<a id="first" href="#">one</a>
<ul id="first_child">
<li>one.1</li>
<li>one.2</li>
</ul>
</li>
</ul>
</body>
<script>
document.getElementById("first").addEventListener("click",nodeAction,false);
function nodeAction(){
if(document.getElementById("first_child").style.display=="block"){ //这里为none时,前两次点击有效,之后无效,搞不懂???
document.getElementById("first_child").style.display="none";
}else{
document.getElementById("first_child").style.display="block";
}
}
</script>
</html>
解决方案 »
- ext在panel中,添加组件,用什么布局可以自动换行?
- window.showModalDialog 为什么不刷新呢
- hover事件如何绑定大box,内部小box经过时发生事情?
- jquery基础
- 新手,求教鼠标事件
- 关于下拉列表的问题
- 如何屏蔽用户在键盘上按shift和ctrl
- JavaScript生成树的问题!!!!!!!!!!!!
- 请问各位:如何让JAVA小程序做的水波纹效果自动显示,自动下载JAVA虚拟机?
- <form method="post" name="form1" action="test.asp" onsubmit="return checkreg(form1);" >有问题?
- 在方法中使用this做为参数的问题
- window.opener.location.href 跨域访问 在IE6,IE7,IE8等IE浏览器中无效
function nodeAction(){
if(document.getElementById("first_child").style.display=="none"){ //这里为none时,前两次点击有效,之后无效,搞不懂???
document.getElementById("first_child").style.display="block";
}else{
document.getElementById("first_child").style.display="none";
}
}
function nodeAction(){
if(document.getElementById("first_child").style.display=="none"){
document.getElementById("first_child").style.display="block";
}else{
document.getElementById("first_child").style.display="none";
}
}