<div id="aaa">aaa</div>
<script>
function contains(p,o){//判断指定节点是否包含在容器中
if(p.contains)return p.contains(o);
do{if(p==o)return true;}while(o=o.parentNode);//有些浏览不支持contains方法需要自己遍历父节点
return false;
}
document.onclick=function(e){
e=e||window.event;
var o=e.target||e.srcElement,a=document.getElementById('aaa');
if(!contains(aaa,o))aaa.style.display='none'
}</script>
<script>
function contains(p,o){//判断指定节点是否包含在容器中
if(p.contains)return p.contains(o);
do{if(p==o)return true;}while(o=o.parentNode);//有些浏览不支持contains方法需要自己遍历父节点
return false;
}
document.onclick=function(e){
e=e||window.event;
var o=e.target||e.srcElement,a=document.getElementById('aaa');
if(!contains(aaa,o))aaa.style.display='none'
}</script>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货