怎样做点击窗口外部关闭窗口?

以往我做这个事情靠一个变量来实现,假设dom结构是这样的

<div title="点击我隐藏内部的div" id="container">

       <div title="点击container关闭我" id="box">

       </div>

</div>

box的onclick 设置box_flag=true;

container的onclick:

if(box_flag)

box_flag=false;

else

//隐藏box

=======================================================================

但现在只要在box的onclick里面调用下面的函数,container的onclick直接隐藏box就ok,更高端,有档次偷笑

function stopEvent(e){
	try{
		if (window.event) {
			window.event.cancelBubble = true;
		} else e.stopPropagation();
	}catch(e){
		trace("stopEvent error="+e);
	}
}

stopEvent(window.event||event);

原文地址:https://www.cnblogs.com/lein317/p/5067594.html