微信小程序如果VIEW绑定点击事件,而且绑定的VIEW中存在许多子元素,会出现一下问题:
在回调函数中使用e.target来获取消息,虽然触发了点击事件,但是传递的消息是空值,只有点击在空白区域才会返回有效值。
解决方法:使用e.currentTarget来获取消息。
js回调函数:
DevTuchCall:function(e){
console.log('有按键按下啦:::');
console.log(e.currentTarget.id);
}
wxml代码
<view wx:for="{{DevList}}"class="top-box"bindtap="DevTuchCall" wx:key="*this" id="{{item.type}}">
<image src="{{item.unique}}"class="devlog" />
<view class="userinfo">
<text >{{item.name}}</text>
<text >ID:{{item.mac}}</text>
</view>
<image src="../image/arrow-r.png"class="arrowlog" />
</view>