Home > Article > Backend Development > javascript - After clicking the physical return button on the phone on the WeChat page, does the page click event fail?
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>
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.