js点击按钮div显示,点击div或者body和按钮,div隐藏

var box = document.getElementById("box");
var btn = document.getElementById("btn"); btn.onclick = function(event){
event.stopPropagation();
if(box.style.display == "none"){
box.style.display = "block";
}else{
box.style.display = "none";
}
};
window.onclick = function(){
box.style.display = "none"
};

  前提是要给div加一个行内的display:none;

上一篇:Django--Hello


下一篇:log4j使用感受