<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
display: flex;
flex-direction: column;
align-items: center;
}
ul li{
list-style: none;
}
ul{
padding-left:0px;
display: none;
}
li{
border: 1px solid #000;
padding: 5px;
cursor: pointer;
}
li:hover{
background: pink;
}
</style>
</head>
<body>
<div>
<button>账号</button>
<div><ul><li>qq</li><li>微信</li><li class="close">关闭</li></ul></div>
</div>
<script>
window.onload=function(){
var oBtn=document.getElementsByTagName('button')[0]
var oUl=document.getElementsByTagName('ul')[0]
var oClose=document.getElementsByClassName('close')[0]
oBtn.onclick=function(){
oUl.style.display=(oUl.style.display=='block'?'none':'block')
}
oClose.onclick=function(){
oUl.style.display='none'
}
}
</script>
</body>
</html>
2.1下拉菜单
最新推荐文章于 2022-12-04 22:53:18 发布