记录
实现下拉框效果……
1、点击一下,出现下拉框
2、再点击一下。复原
图一、
图二、
//总代码
<!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>
body {
margin: 0;
padding: 0;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
.box {
margin: 0 auto;
width: 100px;
height: 40px;
cursor: pointer;
border: 1px solid #cccccc;
text-align: center;
line-height: 40px;
color: #ffffff;
background-color: #c81623;
}
ul {
display: none;
}
ul li {
width: 100px;
height: 40px;
border: 1px solid #cccccc;
text-align: center;
line-height: 40px;
color: #ffffff;
background-color: #666666;
}
</style>
</head>
<body>
<div class="box">
<div>点击一下</div>
<ul>
<li>魏晨</li>
<li>乔燃</li>
<li>叶烁</li>
</ul>
</div>
<script>
var box = document.querySelector('.box');
var ul = document.querySelector('ul');
var flag = 0;
box.onclick = function() {
if (flag == 0) {
ul.style.display = 'block';
flag = 1;
} else {
ul.style.display = 'none';
flag = 0;
}
}
</script>
</body>
</html>