赞
踩
微信小程序的事件请参考:https://mp.weixin.qq.com/debug/wxadoc/dev/framework/view/wxml/event.html。在这里不必啰嗦。
我们都知道bindtap和catchtap都是当用户点击该组件的时候会在该页面对应的Page中找到相应的事件处理函数。但是bind事件绑定不会阻止冒泡事件向上冒泡,catch事件绑定可以阻止冒泡事件向上冒泡。如:
- <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")
- },
- })
- <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")
- },
- })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。