<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
ul,
li {
list-style: none;
padding: 0px;
margin: 0px;
}
li {
border: 1px solid #cccccc;
border-top: none;
text-align: center;
cursor: pointer;
}
ul {
border-top: 1px solid #cccccc;
width: 200px;
margin-left: 60px;
display: none;
}
h4 {
cursor: pointer;
margin-left: 30px;
display: inline;
}
#inputContent {
display: inline-block;
}
</style>
<body>
<!-- 点击鼠标弹出下拉列表 -->
<div>
<div class="title">
<h4 id="haha">请点击一下:</h4>
<div id='inputContent'></div>
<ul class="tabSelet">
<li>1111</li>
<li>2222</li>
<li>3333</li>
<li>4444</li>
</ul>
</div>
</div>
</body>
<script>
window.onload = getClick();
function getClick() {
var titleClick = document.getElementsByTagName('h4')
var ulTab = document.getElementsByClassName('tabSelet');
titleClick[0].addEventListener('click', function(event) {
event = event || window.event;
ulTab[0].style.display = 'block';
event.stopPropagation();
})
document.addEventListener('click', function(event) {
event = event || window.event;
ulTab[0].style.display = "none";
event.stopPropagation();
})
ulTab[0].addEventListener('click', function(event) {
event = event || window.event;
ulTab[0].style.display = "block";
// console.log(event.target);
input_content = document.getElementById('inputContent');
input_content.innerText = event.target.innerText;
event.stopPropagation();
})
}
</script>
</html>