微信小程序bindtap普通事件传参方法

使用bindtap在组件中绑定一个事件处理函数,当用户点击该组件的时候会在该页面对应的Page中找到相应的事件处理函数。

使用data-* 进行传参,

<view id="tapTest" data-hi="Weixin" bindtap="tapName"> Click me! </view>

在相应的Page定义中写上相应的事件处理函数,参数是event。

Page({
    
    
  tapName: function(event) {
    
    
    console.log("获取参数hi:",event.currentTarget.dataset.hi)
  }
})
catchtap:绑定并阻止事件冒泡

官方文档:
https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxml/event.html

猜你喜欢

转载自blog.csdn.net/qq_34661750/article/details/115718433