js点击出现场层层外点击层消失的代码 时间:2020-05-12 人气:0 点击一个连接显示层~点击其他区域隐藏 练习 by <script language="JavaScript" type="text/javascript"> function addListener(element,e,fn){ if(element.addEventListener){ element.addEventListener(e,fn,false); } else { element.attachEvent("on" + e,fn); } } addListener(document,"click",function(evt){ var evt = window.event?window.event:evt,target=evt.srcElement||evt.target; if(target.id == "showDiv"){ document.getElementById("myDiv").style.display = ""; return; }else{ while(target.nodeName.toLowerCase() != "div" && target.nodeName.toLowerCase() != "html"){ target = target.parentNode; } if(target.nodeName.toLowerCase() == "html"){ document.getElementById("myDiv").style.display = "none"; } } }) </script> [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容