以往我做这个事情靠一个变量来实现,假设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);