`
luhantu
  • 浏览: 199899 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

stopImmediatePropagation&stopPropagation 区别

    博客分类:
  • AS3
 
阅读更多

stopImmediatePropagation 与 stopPropagation 不同之处 请仔细查看加粗的文字并结合图例理解。

 

 

stopImmediatePropagation 防止对事件流中当前节点和所有后续节点中的事件侦听器进行处理。此方法会立即生效,并且会影响当前节点中的事件侦听器。

 

stopPropagation  防止对事件流中当前节点的后续节点中的所有事件侦听器进行处理。此方法不会影响当前节点 (currentTarget) 中的任何事件侦听器。

 

测试代码:

 

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx"
			   minWidth="955" minHeight="600" 
			   initialize="application1_initializeHandler(event)">
	
	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;
			protected function application1_initializeHandler(event:FlexEvent):void
			{
				btn.addEventListener(MouseEvent.CLICK,handler1);
				btn.addEventListener(MouseEvent.CLICK,handler2,false,1);
				group.addEventListener(MouseEvent.CLICK,handler3);
				this.addEventListener(MouseEvent.CLICK,handler4);
			}
			
			private function handler1(event:MouseEvent):void
			{
				trace("btn priority 0 handler");
				event.stopPropagation();
				
			}
			
			private function handler2(event:Event):void
			{
				trace("btn priority 1 handler");
			}
			
			private function handler3(event:Event):void
			{
				trace("group handler");
			}
			
			
			private function handler4(event:Event):void
			{
				trace("app handler");
			}
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	<s:Group id="group">
		<s:Button label="Click" id="btn"/>
	</s:Group>
</s:Application>

 

event.stopPropagation(),结果:

btn priority 1 handler

btn priority 0 handler

 

event.stopImmediatePropagation (),结果:

btn priority 1 handler

  • 大小: 33.1 KB
0
0
分享到:
评论

相关推荐

    ng-event-options:在角度模板中启用事件选项(捕获,被动,...)

    stopImmediatePropagation , stopPropagation和preventDefault其他事件选项 事件操作员对throttle和debounce支持 用于在NgZone外部NgZone并且仅在platformBrowser内部绑定的角度事件选项 该模块仅压缩3KB ,因此...

    js实现的点击div区域外隐藏div区域

    阻止冒泡:1、stopPropagation()对于非IE浏览器。2、cancelBubble属性为true,对于IE浏览器, 而Jquery已经有兼容浏览器的方法,event.stopImmediatePropagation(); &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt;...

    DIV外区域Click后关闭DIV的实现代码

    阻止冒泡:1、stopPropagation()对于非IE浏览器。2、cancelBubble属性为true,对于IE浏览器, 而Jquery已经有兼容浏览器的方法,event.stopImmediatePropagation(); 代码如下: &lt;style&gt; body { background:...

    tweenjs.min.js文件

    0},a.stopImmediatePropagation=function(){this.immediatePropagationStopped=this.propagationStopped=!0},a.remove=function(){this.removed=!0},a.clone=function(){return new Event(this.type,this.bubbles,...

    React冒泡和阻止冒泡的应用详解

    1:阻止合成事件往最外层document上的事件冒泡,用e.nativeEvent.stopImmediatePropagation(); 2: 合成事件间的冒泡,使用 e.stopPropagation(); 3:阻止合成事件,往处理document上的其他原生事件冒泡,需要通过e....

    滑动出菜单

    e.stopImmediatePropagation(); obj.state.dragable = true; obj.state.mouseX = e.targetTouches[0].pageX; obj.state.mouseY = e.targetTouches[0].pageY; }); document.addEventListener("touchmove", ...

    jquery需要的所有js文件

    jquery需要的所有js文件 /*! * jQuery UI 1.8.18 * ... * Dual licensed under the MIT or GPL Version 2 licenses. ... * ... */(function(a,b){function d(b){return!a(b).parents().andSelf().filter(function(){return ...

    JQuery_1.4_API开发手册

    (Bug) stopImmediatePropagation was not being honoured in live/delegate event handlers (#7217) (Bug) Fixed an issue where host and protocol were not compared case-insensitively when determining ...

    jQuery最新1.4.4精简版+1.4中文手册

    (Bug) stopImmediatePropagation was not being honoured in live/delegate event handlers (#7217) (Bug) Fixed an issue where host and protocol were not compared case-insensitively when determining ...

    jQuery 1.5 API 中文版

    stopImmediatePropagation(), stopPropagation(), eltarget, numtimeStamp, strtype, strwhich } Effects Basics $.show( [ duration [, easing] [, fn] ] ) $.hide( [ duration [, easing] [, fn] ] ) $.toggle( ...

Global site tag (gtag.js) - Google Analytics