小程序for循环中通过index实现单个点击事件


<!--xml-->
<view class='content3-list' wx:for="{{listItems}}" >
<view class='list-left'>
<image id="{{index}}" bindtap='clickRight' src= '{{item.rightImage}}' />
<text class='list-left-wd'>{{item.word}}</text>
<text class='list-left-exp'>{{item.explain}}</text>
</view>
<view class='list-right'>
<image src="../../images/del.png" />
</view>
</view>
 
<!--js-->
Page({
// 页面的初始数据
data: {
listItems: [
{
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}, {
"rightImage": "/images/right.png",
"word": "book",
"explain": "书;卷;课本;账簿"
}
]
},
clickRight: function (e) {
var idx = parseInt(e.currentTarget.id);
var img = this.data.listItems;
if ("/images/right.png" == img[idx].rightImage) {
img[idx].rightImage = "/images/right1.png";
} else {
img[idx].rightImage = "/images/right.png";
}
}
})



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM