Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the order of jQuery event flow

零下一度
Release: 2017-06-17 17:38:34
Original
1339 people have browsed it

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>
Copy after login

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;) })
Copy after login

Triggered result:

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

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!