Emulate W3C event capturing model in IE

前端 未结 6 1368
野趣味
野趣味 2021-02-07 11:54

Is it possible to emulate event capturing in Internet Explorer?

An example:

one
two
three3



        
6条回答
  •  南笙
    南笙 (楼主)
    2021-02-07 12:19

    Generally you can't because of the event order. In IE the events will start bubbling from the target element without the capturing phase so you can't catch them beforehand.

    There's only one thing you can do, and it's only possible if you manage all the event handlers.

    1. Write a wrapper for addEvent with capture parameter
    2. If capturing is required do the following

      1. Register a simple bubbling event, with a function that
      2. Goes all the way up the parent chain, saving all the elements to an Array
      3. Travels backward this Array invoking the original event handler on each of the elements

提交回复
热议问题