-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
117 lines (116 loc) · 2.46 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
#oUl li ul{
display: none;
}
#oUl li ul.show{
display: block;
}
#oUl li ul.hide{
display: none;
}
li{
list-style: none;
}
</style>
</head>
<body>
<ul id="oUl"></ul>
</body>
<script>
var arr = [
{
title : "第一级菜单",
child : [
{title:"第二集菜单"},
{title:"第二集菜单",
child:[
{title:"第三集菜单"},
{title:"第三集菜单",
child:[
{title:"第四集菜单"},
{title:"第四集菜单"},
{title:"第四集菜单"}
]
},
{title:"第三集菜单"}
]
},
{
title:"第二集菜单",
child:[
{title:"第三集菜单"},
{title:"第三集菜单"}
]
}
]
},
{
title : "第一级菜单",
child : [
{title:"第二集菜单"},
{title:"第二集菜单",
child:[
{title:"第三集菜单"},
{title:"第三集菜单",
child:[
{title:"第四集菜单"},
{title:"第四集菜单"},
{title:"第四集菜单"}
]
},
{title:"第三集菜单"}
]
},
{
title:"第二集菜单",
child:[
{title:"第三集菜单"},
{title:"第三集菜单"}
]
}
]
},
{
title:"第一集菜单",
child:[
{title:"第二集菜单"},
{title:"第二集菜单"}
]
},
];
var oUl=document.getElementById("oUl");
function fn(myarr,obj){
for (var i=0;i<myarr.length;i++) {
var li=document.createElement("li");
for(var attr in myarr[i]){
if(attr=="title"){
var h2=document.createElement("h2");
h2.innerHTML= myarr[i][attr];
li.appendChild(h2);
}
if(attr=="child"){
var ul=document.createElement("ul");
ul.className="hide";
h2.innerHTML="+"+h2.innerHTML;
h2.onclick=function(){
if(this.nextElementSibling.className=="hide"){
this.nextElementSibling.className="show";
}else{
this.nextElementSibling.className="hide";
}
}
li.appendChild(ul);
fn(myarr[i][attr],ul)
}
}
obj.appendChild(li)
}
}
fn(arr,oUl);
</script>
</html>