1. Direct use method:
catchtouchmove
=
"preventD"
<
view
class
=
"selector-bj {{isTapSelector ? '' : 'is-focus-selector' }}"
wx:if
=
"{{selectorBj}}"
bindtap
=
'tapSeleBj'
catchtouchmove
=
"preventD"></
view
>
//Prevent clicks from penetrating the background layer
preventD:
function
(){
},
2. Use catch instead of bind
bind
Event binding does not prevent bubbling events from bubbling upwards, catch
event binding prevents bubbling events from bubbling upwards.
As in the example below, clicking on the inner view will call handleTap3
and handleTap2
(because the tap event will bubble up to the middle view, and the middle view prevents the tap event from bubbling and is no longer passed to the parent node), clicking on the middle view will trigger handleTap2
, click outer view will fire handleTap1
.
<view id="outer" bindtap="handleTap1">
outer view
<view id="middle" catchtap="handleTap2">
middle view
<view id="inner" bindtap="handleTap3">
inner view
</view>
</view>
</view>