要求
1、点击一级菜单,如果当前二级菜单是打开状态则二级菜单收起,小图标变成+
如果当前二级菜单是关闭状态则展开二级菜单,小图标变成- 并且收起其他的二级菜单
2、页面中的二级菜单最多只能有一个是展开状态
方法一:
<html>
<head>
<title>1. 实现伸缩二级菜单</title>
<meta charset="utf-8" />
<style>
li{
list-style:none;
}
li span {
padding-left:20px;
cursor:pointer;
}
.open{
background:url("img/minus.png") no-repeat center left;
}
.closed{
background: url("img/add.png") no-repeat center left;
}
.show{display:block;}
.hide{display:none;}
</style>
<script type="text/javascript">
window.onload = function (){
var Allspan = document.getElementsByTagName('span');
for(var i = 0 ; i<Allspan.length; i++){
Allspan[i].onclick=function(){
if(this.className =="open"){
this.className = "closed";
this.nextElem