希望大神们help一下,我设置了很多button,希望点击每一个button各自出现四张不一样的图片。
<button class=“post” style=“margin-top:8%;” bindtap=“touchBtn” hover-class=“hoverclass” data-id=“1”>大门</button>
<button class=“post” style=“margin-top:17%;” bindtap=“touchBtn” hover-class=“hoverclass” data-id=“2”>教学楼</button>
<button class=“post” style=“margin-top:26%;” bindtap=“touchBtn” hover-class=“hoverclass”>食堂</button>
<button class=“post” style=“margin-top:35%;” bindtap=“touchBtn” hover-class=“hoverclass”>快递</button>
<button class=“post” style=“margin-top:44%;” bindtap=“touchBtn” hover-class=“hoverclass”>ATM</button>
<button class=“post” style=“margin-top:53%;” bindtap=“touchBtn” hover-class=“hoverclass”>体育场</button>
<button class=“post” style=“margin-top:62%;” bindtap=“touchBtn” hover-class=“hoverclass”>景点</button>
<button class=“post” style=“margin-top:71%;” bindtap=“touchBtn” hover-class=“hoverclass”>教超</button>
<image class=“image-style” src="{{imgArr[0]}}"></image>
<image class=“image-style” src="{{imgArr[1]}}"></image>
<image class=“image-style” src="{{imgArr[2]}}"></image>
<image class=“image-style” src="{{imgArr[3]}}"></image>
对的我刚学这个 但是我改了还是错的
var imgArr = [];
Page({
data:{
scrollTop:100,
array: [‘宝山’,‘嘉定’,‘延长’]
},
bindPickerChange: function (e) {
console.log(‘picker发送选择改变,携带值为’, e.detail.value)
this.setData({
index: e.detail.value
})
},
upper:function(e){
console.log(e)
},
lower:function(e){
console.log(e)
},
scroll: function (e){
console.log(e)
},
touchBtn: function (e) {
var data = e.currentTarget.dataset.id;
if (data == 1) {//大门
imgArr = [“images/1.png”, “images/2.png”, “images/3.png”, “images/4.jpg”];//存储要展示的图片
} else if (data == 2) {//教学楼
imgArr = [“images/1.png”, “images/2.png”, “images/3.png”, “images/4.jpg”];//存储要展示的图片
}
this.setData({
imgArr: imgArr,
})
}
})