一.wxml页面设计代码:
<view class='top_view' style='color:{{pageBackgroundColor}}'>欢迎来到休闲游戏页面</view>
<view class="clik_view" bindtap='ChangColor'>点击切换背景颜色</view>
二.js控制颜色的变化代码:
// 改变字体颜色
ChangColor: function () {
var bgColor = this.data.pageBackgroundColor == 'red' ? '#5cb85c' : 'red';
// 设置字体颜色数据
this.setData({
pageBackgroundColor: bgColor
});
}