点击按钮的时候,弹出菜单。点击其他地方的时候,隐藏菜单。代码如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<style>
div {
width:100px;
height:150px; background:#ccc;display:none;
}
</style>
<script>
window.onload = function () {
var oBtn = document.getElementById("btn1");
var oDiv = document.getElementById("div1");
oBtn.onclick = function (ev) {
var oEvent = ev || event;
oDiv.style.display = "block";
ev.cancelBubble = true;
};
document.onclick = function () {
oDiv.style.display = "none";
}
}
</script>
</head>
<body>
<button id="btn1">显示</button>
<div id="div1"></div>
</body>
</html>
转载于:https://www.cnblogs.com/XChWaad/p/4910151.html