小程式屬性單項選擇
阿新 • • 發佈:2018-11-10
話不多說,先看效果圖:
下面直接貼程式碼:
wxml:
<!-- 選擇顏色 --> < view class= "Choosecolor"> < view class= "colortext">選擇顏色 </ view > < view class= "colorview"> < view class= "{{curIndex==index ?'itemview':'itemviewss'}}"css:
js;
Page({data: { itemview: false, color: [ { color: "紅色" }, { color: "橙色" }, { color: "黃色" }, ] },
ChooseColor: function (res) { var that = this console.log( "你選的是:", res.target.dataset.item.color) var index = res.target.dataset.index console.log(index, "index index ") console.log(that.data.itemview, "that.data.itemview ")
if (that.data.itemview == false) { that.setData({ itemview: true, }) } else { that.setData({ itemview: false }) } that.setData({ curIndex: index, title: res.target.dataset.item.color }) },
})