大家好,又见面了,我是你们的朋友全栈君。
微信小程序之事件(bindtap和catchtap)
微信小程序的事件请参考:https://mp.weixin.qq.com/debug/wxadoc/dev/framework/view/wxml/event.html。在这里不必啰嗦。 我们都知道bindtap和catchtap都是当用户点击该组件的时候会在该页面对应的Page中找到相应的事件处理函数。但是bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒泡事件向上冒泡。如:
代码语言:javascript复制<view id="outer" bindtap="handleTap1">
outer view
<view id="middle" catchtap="handleTap2">
middle view
<view id="inner" bindtap="handleTap3">
inner view
</view>
</view>
Page({
handleTap1:function(event){ //点击输出outer view bindtap
console.log("outer view bindtap")
},
handleTap2: function (event) { //点击输出middle view
console.log("middle view catchtap")
},
handleTap3: function (event) { //点击输出inner view bindtap middle view catchtap
console.log("inner view bindtap")
},
})
代码语言:javascript复制<view id="outer" bindtap="handleTap1">
outer view
<view id="middle" bindtap="handleTap2">
middle view
<view id="inner" bindtap="handleTap3">
inner view
</view>
</view>
Page({
handleTap1:function(event){ //点击输出outer view bindtap
console.log("outer view bindtap")
},
handleTap2: function (event) { //点击输出outer view bindtap middle view
console.log("middle view catchtap")
},
handleTap3: function (event) { //点击输出outer view bindtap inner view bindtap middle view catchtap
console.log("inner view bindtap")
},
})
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/124730.html原文链接:https://javaforall.cn