<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#clickOpen
{
padding:5px 10px;
background-color: blueviolet;
display: inline-block;
}
.list
{
list-style: none;
display: inline-block;
background-color: blueviolet;
padding: 0px 20px;
display: none;
}
</style>
</head>
<body>
<div id="clickOpen">点击展开</div>
<br>
<ul class="list">
<li class="item">目录1</li>
<li class="item">目录2</li>
</ul>
<script>
var clickbtn = document.getElementById('clickOpen');
var list = document.getElementsByClassName('list')[0];
var isopen = false;
clickbtn.addEventListener('click',function()
{
isopen = !isopen;
if(isopen)
{
clickbtn.innerHTML = '点击隐藏';
list.style.display = 'inline-block';
}
else
{
clickbtn.innerHTML = '点击展开';
list.style.display = 'none';
}
})
</script>
</body>
</html>