Home  >  Article  >  Web Front-end  >  Detailed explanation of the order of jQuery event flow

Detailed explanation of the order of jQuery event flow

零下一度
零下一度Original
2017-06-17 17:38:341300browse

Provide you with jQueryEvent flow sequence and other resources, you are welcome to bookmark this site, we will provide you with the latest jQuery event flow sequence resources

<p id="aaron">    <p id=&#39;test&#39;>         <ul>             <p>点击p被委托,ul被阻止了,因为内部重写了事件对象</p>         </ul>    </p> </p>v>

Test code

var aaron = $("#aaron") //同一个元素上绑定不同的事件委托 aaron.on(&#39;mousedown&#39;,&#39;p&#39;,function(e){     console.log(&#39;委托到p触发&#39;)   // e.stopPropagation() }) aaron.on(&#39;mousedown&#39;,&#39;ul&#39;,function(e){     console.log(&#39;被阻止了&#39;) })  aaron.on(&#39;mousedown&#39;,function(e){   console.log(&#39;mousedown&#39;) })  $("#test").on(&#39;mousedown&#39;,function(){   console.log(&#39;test&#39;) })  $("body").on(&#39;mousedown&#39;,function(){   console.log(&#39;body&#39;) })

Triggered result:

test 委托到p触发 被阻止了 mousedown body

According to the event flow of W3C, the target is captured and bubbled

can be seen

Although the p, ul node contacts the target earlier than the #test p node, because p, ul is bound to the bubble on #aaron p, the priority is lower than #test

But the priority of the same element depends on the nesting order of the elements. Anyway, the closer a sentence is to the target, the sooner it will be triggered

The above is the detailed content of Detailed explanation of the order of jQuery event flow. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:jQuery size algorithmNext article:jQuery size algorithm