-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path多级菜单2.html
92 lines (84 loc) · 2.02 KB
/
多级菜单2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>$Title$</title>
<style>
* {
margin: 0;
padding: 0;
}
ol, ul {
list-style: none;
}
a {
text-decoration: none;
}
#main li {
width: 100px;
background-color: antiquewhite;
}
#main li a {
/*width: 100%;*/
/*height: 100%;*/
display: block;
line-height: 30px;
text-align: center;
cursor: default;
}
#main ul {
display: none;
}
#main ul li {
height: 30px;
width: 100px;
border-bottom: 1px dashed;
text-align: center;
line-height: 30px;
background-color: aliceblue;
}
</style>
</head>
<body>
<ul id="main">
<li class="main-menu">
<a href="#">Link1</a>
<ul>
<li>sublink1</li>
<li>sublink2</li>
<li>sublink3</li>
</ul>
</li>
<li class="main-menu">
<a href="#">Link2</a>
<ul>
<li>sublink1</li>
<li>sublink2</li>
<li>sublink3</li>
</ul>
</li>
</ul>
<script>
var oUl = document.getElementById("main");
var aLi = oUl.getElementsByTagName("li");
var bShow = false; //false代表隐藏状态
for (var i = 0; i < aLi.length; i++) {
if (aLi[i].className = "main-menu") {
aLi[i].onclick = function () {
var oUl2 = this.getElementsByTagName("ul")[0];
if (bShow) {
oUl2.style.display = "none";
bShow = !bShow;
console.log(oUl2.style.display);
}
else {
oUl2.style.display = "block";
bShow = !bShow;
console.log(oUl2.style.display);
}
}
}
}
</script>
</body>
</html>