微信小程序-单选


wxml
<view class='taskAll_pic'>
<view class='titleTxet'>图片</view>
<view class='picBgInput'>
<view wx:for='{{changeList}}' wx:for-item='item' class='imgFath' bindtap='changePic' data-index='{{index}}'>
<image class='changShow' src='{{item.isSeleted==false?item.icon:sleectedIcon}}'></image>
<image class='changImg' src='{{item.img}}'></image>
</view>
</view>
</view>
 
js
 
changeList: [
{ "icon": "/images/attic/round.png", "img": "/images/attic/father.png", 'isSeleted': false },
{ "icon": "/images/attic/round.png", "img": "/images/attic/good.png", 'isSeleted': false },
{ "icon": "/images/attic/round.png", "img": "/images/attic/mather.png", 'isSeleted': false },
{ "icon": "/images/attic/round.png", "img": "/images/attic/my.png", 'isSeleted': false },
{ "icon": "/images/attic/round.png", "img": "/images/attic/tv.png", 'isSeleted': false }
],
// 选择 图片
changePic(e){
if (this.data.changeList[e.currentTarget.dataset.index].isSeleted == false){
this.data.changeList[e.currentTarget.dataset.index].isSeleted = true
}

if (this.data.changeList[e.currentTarget.dataset.index].isSeleted == true){
for (let ii in this.data.changeList){
//下标不为 e.currentTarget.dataset.index 全为 false
if ( ii != e.currentTarget.dataset.index){
this.data.changeList[ii].isSeleted = false;
}
}
}

this.setData({
changeList: this.data.changeList,
icon: this.data.changeList[e.currentTarget.dataset.index].img
})

console.log(this.data.icon)

},


免责声明!

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



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