美文网首页
元素套着元素点击事件 (自定义属性)之穿透

元素套着元素点击事件 (自定义属性)之穿透

作者: 程序媛可可 | 来源:发表于2020-09-17 21:49 被阅读0次

举例

<view 
wx:for="{{selectArr}}" wx:key='*this' 
 class="selectimage 
bindtap="selectClick"  点击事件
data-myindex="{{index}}" //自定义事件
 >
  <image  mode="widthFix" src="{{item}}"></image>
 </view>

此时我们在点击事件console.log(e)

 selectClick(e){
    console.log(e);
  },

原本应该打印出来的是

image.png

我们可以通过 e.target.dataset.myindex 获取到自定义属性的值

=========================================================================================

但是因为穿透了所以会形成

image.png

所以我们需要通过 e.target.currentarget.myindex获取到自定义属性的值

相关文章

网友评论

      本文标题:元素套着元素点击事件 (自定义属性)之穿透

      本文链接:https://www.haomeiwen.com/subject/aqvryktx.html