wxml:
<view > <button class="show" bindtap="onChangeShowState">{{showView?'隐藏':'显示'}}</button> </view> <view class="hide{{showView?'show':''}}"> <text class="text">我是被隐藏控件</text> </view>
wxss:
.hide{ display: none; } .show{ display: block; }
js:
Page({ data: { showView: true }, onLoad: function (options) { showView: (options.showView == "true" ? true : false) } , onChangeShowState: function () { var that = this; that.setData({ showView: (!that.data.showView) }) } })
另一种方式:
wxml:
<image src="{{showView?'http://192.168.2.61/wap/rm/images/select.png':'http://192.168.2.61/wap/rm/images/selected.png'}}" bindtap="onChangeShowState"></image>
js:
showView:true; onChangeShowState: function () { var that = this; that.setData({ showView: (!that.data.showView) }) }