-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path多级菜单从兄弟查找.html
83 lines (79 loc) · 1.73 KB
/
多级菜单从兄弟查找.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<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">
<h3>Link1</h3>
<ul class="sub-menu">
<li>sublink1</li>
<li>sublink2</li>
<li>sublink3</li>
</ul>
</li>
<li class="main-menu">
<h3>Link2</h3>
<ul class="sub-menu">
<li>sublink1</li>
<li>sublink2</li>
<li>sublink3</li>
</ul>
</li>
</ul>
<script>
var oUl=document.getElementById("main");
var aH3=oUl.getElementsByTagName("h3");
for(var i=0;i<aH3.length;i++)
{
aH3[i].onclick = function () {
console.log(next(this));
next(this).style.display = "block";
}
}
function next(elem) {
do {
elem = elem.nextSibling;
}while (elem && elem.nodeType != 1);
return elem
}
</script>
</body>
</html>