WX小程序-点击跳转页面事件

在微信小程序中,大部分标签与HTML类似。但值得注意的是点击事件是通过bindtap属性实现的:

<button bindtap='change'></button>

在该页面的.js文件中,使用wx.navigateTo(),嵌入链接即可。

change: function (param) {
    wx.navigateTo({
      url: '/pages/Messages/m3',
    })//跳转到M3界面。
  },

除了在button标签中包含bindtap属性外,在其他大多数标签中都可以使用,较为方便。相对于bindtap属性,微信小程序还提供了其它针对不同时长的点击事件,包括bindtouchstart、bindtouchend、bindlongpress:

<button 
bindtouchstart="handleTouchStart" 
bindtouchend="handleTouchEnd" 
bindlongpress="handleLongPress" 
bindtap="handleClick">
点击/长按</button> 
//touch start
handleTouchStart: function(e) {    
    this.startTime = e.timeStamp;    
    //console.log(" startTime = " + e.timeStamp);  
},  
 
//touch end
handleTouchEnd: function(e) {    
    this.endTime = e.timeStamp;    
    //console.log(" endTime = " + e.timeStamp);  
},  
 
handleClick: function(e) {    
    //console.log("endTime - startTime = " + (this.endTime - this.startTime));    
    if (this.endTime - this.startTime < 350) {      
    console.log("点击");    
    }  
},  
 
handleLongPress: function(e) {    
//console.log("endTime - startTime = " + (this.endTime - this.startTime));
console.log("长按");  
}

猜你喜欢

转载自blog.csdn.net/qq_42330000/article/details/86695821