Home  >  Article  >  Backend Development  >  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?

WBOY
WBOYOriginal
2016-08-04 09:20:021538browse

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>

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>

Try event delegation

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

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

<code>     ...
     //get请求</code>

});

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

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