<p>WXML</p><pre class="brush:xml;toolbar:false"><viewclass="page"style="background-color:{{pageBackgroundColor}}">
<buttonbindtap="changeColor"hover-class="none">点击修改背景颜色</button>
</view></pre><p>WXSS:</p><pre class="brush:css;toolbar:false">.page{
display:block;
min-height:100%;
width:100%;
position:absolute;
left:0;
top:0;
z-index:1;
}</pre><p>JS:</p><pre class="brush:js;toolbar:false">Page({
data:{
//自定义page对象CSS样式对象
pageBackgroundColor:'#5cb85c'
},
onLoad:function(){},
//改变背景颜色
changeColor:function(){
varbgColor=this.data.pageBackgroundColor=='red'?'#5cb85c':'red';
//设置背景颜色数据
this.setData({
pageBackgroundColor:bgColor
});
}
})</pre>