-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12-手风琴.html
99 lines (83 loc) · 2.51 KB
/
12-手风琴.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
ul {
list-style-type: none;
}
.parentWrap {
width: 200px;
text-align: center;
}
.menuGroup {
border: 1px solid #999;
background-color: #e0ecff;
}
.groupTitle {
display: block;
height: 20px;
line-height: 20px;
font-size: 16px;
border-bottom: 1px solid #ccc;
cursor: pointer;
}
.menuGroup > div {
height: 200px;
background-color: #fff;
display: none;
}
</style>
</head>
<body>
<ul class="parentWrap">
<li class="menuGroup">
<span class="groupTitle">标题1</span>
<div>我是弹出来的div1</div>
</li>
<li class="menuGroup">
<span class="groupTitle">标题2</span>
<div>我是弹出来的div2</div>
</li>
<li class="menuGroup">
<span class="groupTitle">标题3</span>
<div>我是弹出来的div3</div>
</li>
<li class="menuGroup">
<span class="groupTitle">标题4</span>
<div>我是弹出来的div4</div>
</li>
</ul>
</body>
<script src="./jquery-2.2.2.js"></script>
<script>
/*
思路:
给li注册点击事件,把自己的子元素div显示 出来,把别人的子元素div隐藏
获取li,注册点击事件
*/
//获取li,注册点击事件
// $('.menuGroup').on('click',function(){
// // 先把自己的子元素div显示
// // jq对象.children(筛选的选择器)
// $(this).children('div').css('display','block');
// // 把别人的子元素div隐藏
// $(this).siblings().children('div').css('display','none');
// })
$('.menuGroup').on('click',function(){
// let ch = $(this).children('div').css('display','block');
// console.log(ch);
// 一行代码搞定所有功能
/* jq对象.parent() */
// 通过div获取父元素,再找到叔叔伯伯,在找到堂兄弟,把他们埋起来
// let p = $(this).children('div').css('display','block').parent();
// console.log(p);
$(this).children('div').css('display','block').parent().siblings().children('div').css('display','none');
})
</script>
</html>