小程式可重複點選的按鈕(false和true)
阿新 • • 發佈:2018-11-10
程式碼如下
wxml:
<
view
class=
'{{san?"v1":"v2"}}'
bindtap=
"selectList"></
view
>
css: .v1 { width: 100 rpx; height: 100 rpx; background: red; border-radius: 50 rpx ;
}
.v2 { width: 100 rpx; height: 100 rpx; background: gray; border-radius: 50 rpx; }
data: { san: true, i: 1, //變數
}, // 宣告一個變數,並判斷這個變數
selectList:
function () {
var that =
this;
console.log(that.data.i,
"i")
if (that.data.i ==
1) {
that.data.i =
2,
that.setData({
san:
false,
})
}
else {
that.data.i =
1 ,
that.setData({
san:
true,
})
}
console.log(that.data.i,
"i2222")
},
})
css: .v1 { width: 100 rpx; height: 100 rpx; background: red; border-radius: 50 rpx
.v2 { width: 100 rpx; height: 100 rpx; background: gray; border-radius: 50 rpx; }
js:
Page({data: { san: true, i: 1, //變數
}, // 宣告一個變數,並判斷這個變數
})