Home > Backend Development > PHP Tutorial > javascript - After clicking the physical return button on the phone on the WeChat page, does the page click event fail?

javascript - After clicking the physical return button on the phone on the WeChat page, does the page click event fail?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-04 09:20:02
Original
1582 people have browsed it

During the development process of the WeChat public account site, a page was cyclically bound to a click event. After switching to another page and returning through the physical return key of the phone, the click event became invalid. I don’t know why?

<code>$(function(){
  //点击事件
  var mapList=$(".map .loc-tag");
  $.each(mapList,function(index,item){
      mapList.eq(index).on('click',function(){
         ...
         //get请求
      });
  });
});</code>
Copy after login
Copy after login

Reply content:

During the development process of the WeChat public account site, a page was cyclically bound to a click event. After switching to another page and returning through the physical return key of the phone, the click event became invalid. I don’t know why?

<code>$(function(){
  //点击事件
  var mapList=$(".map .loc-tag");
  $.each(mapList,function(index,item){
      mapList.eq(index).on('click',function(){
         ...
         //get请求
      });
  });
});</code>
Copy after login
Copy after login

Try event delegation

var hastouch = "ontouchstart" in window ? true : false,
start = hastouch ? "touchstart" : "click";

mapList.eq(index).on(start,function(){

<code>     ...
     //get请求</code>
Copy after login

});

I also encountered this problem when I was working on a project before.

Related labels:
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
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template