bindtap 和 catchtap 的区别
bindtap
绑定的事件可以冒泡,事件会向上冒泡到父元素并触发父元素上的绑定事件。
catchtap
绑定的事件不会冒泡,事件不会向上冒泡到父元素,阻止事件传递。
示例
<!-- wxml 文件 -->
<view bindtap="handleParentTap">
Parent
<view bindtap="handleChildTap">Child</view>
<view catchtap="handleChildCatchTap">Child with catchtap</view>
</view>
// js 文件
Page({
handleParentTap: function() {
console.log('Parent tapped');
},
handleChildTap: function() {
console.log('Child tapped');
},
handleChildCatchTap: function() {
console.log('Child tapped (catchtap)');
}
});
点击 Child
会触发 handleChildTap
和 handleParentTap
,而点击 Child with catchtap
只会触发 handleChildCatchTap
。