event flow model

1. event.preventDefault只是取消event的默认action, 比如submit event不会产生POST 请求 ,  2. event.stopPropagation 会停止 bubble两个phase的dispatch 3.event dispatch分为3个阶段  (eventPhase为0, 0:表示当前event没有被触发调度 1>:   capture阶段 2> eventTarget dispatch 阶段, 此时currentEventTarget === eventTarget 3> bubble 阶段, 在html中或者通过DOMNode attribute设置的 on{event} = handler 在这个阶段被调度

      • [Event.NONE 0 No event is being processed at this time.
      • Event.CAPTURING_PHASE
    1. 1 The event is being propagated through the target's ancestor objects. This process starts with the Window, then Document, then the HTMLHtmlElement, and so on through the elements until the target's parent is reached. Event listeners registered for capture mode when EventTarget.addEventListener() was called are triggered during this phase.
      • Event.AT_TARGET
    1. 2 The event has arrived at the event's target. Event listeners registered for this phase are called at this time. If Event.bubbles is false, processing the event is finished after this phase is complete.
    1. 这个阶段,所有注册的event listener都会被执行,及时在当前有一个eventlistener 调用stopPropagation,注意stopPropagation 只是定制 event的调度,但是当前 node上的eventlistener都会一直执行.
      • Event.BUBBLING_PHASE
    1. 3 The event is propagating back up through the target's ancestors in reverse order, starting with the parent, and eventually reaching the containing Window. This is known as bubbling, and occurs only if Event.bubbles is true. Event listeners registered for this phase are triggered during this process.]
    1.  在html中通过 on{event} = xxx的方式定义event handler
  1. 如果在parent node (captured) 中调用了stopPropagation, event不会被调度到 当前node,但是这并不妨碍 当前node执行 defaultaction, 换句话说 如果click event在( input type='submit') 之前被 stopPropagation,但是 <input type='submit'依然能够触发 submit event , 如果想让<input type='submit>不触发submit 只能 在click event handler 中调用 preventDefault()

  2. 在html 设置on{event}=xxx , "xxx"必须是 functionFoo( args),其中args可以是 "this", "event" 这两个是在DOMnode 的context中

转载于:https://my.oschina.net/wansheg/blog/865580

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值