Home > Web Front-end > JS Tutorial > zepto and jQuery on event delegation on iPhone

zepto and jQuery on event delegation on iPhone

一个新手
Release: 2017-10-19 09:19:25
Original
2098 people have browsed it

The page made with zepto on the mobile terminal suddenly found that the click event bound to on was not triggered. The code is as follows:

<ul>  
  <li class="a">1111111aaaaaaasssss</li>  
  <li class="b">aaaaaaassssss</li>  
  <li class="c">ssssssss</li>  
</ul>  

<script>

  $(document).on(&#39;click&#39;,&#39;.c&#39;,function(argument) {  
    alert($(this).html())  
  })  
</script>
Copy after login

I changed this writing method to a non-event delegation method, and found that the click event was It can trigger


$(‘.a’).on(&#39;click&#39;,function(argument) {  
  alert($(this).html())  
});
Copy after login

Finally, try replacing $(document) with $('body') or $('ul'). The experimental result is:

$(document) No

$('body') No

$('ul') OK

The above is the detailed content of zepto and jQuery on event delegation on iPhone. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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