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

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值