<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.list{
width: 400px;
}
.item{
width: 400px;
/*height: 48px;*/
}
.header{
background-color: #dddddd;
}
.hide{
display: none;
}
</style>
</head>
<body>
<div class="list">
<div class="item">
<div class="header">标题一</div>
<div class="content">看看</div>
</div>
<div class="item">
<div class="header">标题二</div>
<div class="content hide">匹配</div>
</div>
<div class="item">
<div class="header">标题三</div>
<div class="content hide">预约</div>
</div>
</div>
<script src="jquery-3.3.1.js"></script>
<script>
<!--用jQuery绑定点击事件-->
$('.header').click(function () {
//移除下一个标签的hide
$(this).next().removeClass('hide');
//找到当前标签的父标签parent--找到父标签的兄弟标签siblings--找到兄弟标签中class为content的标签
$(this).parent().siblings().find('.content').addClass('hide');
})
</script>
</body>
</html>
网友评论