需實現的功能:
點擊按鈕後,按鈕的顏色會加深
效果展示:
原按鈕
點擊後的按鈕
思路:
給按鈕設置一個點擊事件,點擊了按鈕後,修改按鈕的樣式。
代碼:
test.wxml文件
<view wx:if="{{sty==0}}">
<view class="score" style="background-color:{{score}};" catchtap='score'>
<text>按鈕一</text>
</view>
</view>
<view wx:if="{{sty==1}}">
<view class="score" style="background-color:{{score}};" catchtap='score'>
<text>按鈕一</text>
</view>
</view>
test.js文件
Page({
/*** 頁面的初始數據*/
data: {
sty:0,
score: '#fff5df',
},
score: function (e) {
//點擊按鈕,樣式改變
let that = this;
that.setData({
sty: 1,
score: 'rgba(252,178,22, 0.3)'
});
},
)}
test.css文件
.score{
width:335rpx;
border-radius:10rpx 0rpx 0rpx 10rpx;
}
.score text{
color: #FCB216;
}