当前位置:Gxlcms > PHP教程 > javascript-微信页面点击手机物理返回键后,页面点击事件失效?

javascript-微信页面点击手机物理返回键后,页面点击事件失效?

时间:2021-07-01 10:21:17 帮助过:21人阅读

在微信公众号站点开发过程功能中,一个页面循环绑定了点击事件,在切换到另一个页面再通过手机物理返回键返回之后,点击事件就失效了,不知是何原因?

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

回复内容:

在微信公众号站点开发过程功能中,一个页面循环绑定了点击事件,在切换到另一个页面再通过手机物理返回键返回之后,点击事件就失效了,不知是何原因?

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

试试事件委托

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

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

     ...
     //get请求

});

之前我做一个项目的时候也遇到这个问题。

人气教程排行