一個(gè)開關(guān)的按鈕。我想做成一個(gè)開狀態(tài)下點(diǎn)擊之后顯示關(guān)。關(guān)狀態(tài)下再點(diǎn)一下顯示開
網(wǎng)友回復(fù):
.js
page({
data:{
isopen:true,
state:“開”
},
buttontap:function(){
if(this.data.isopen){
this.setData({
state:"關(guān)"
})
}else{
state:"開"
}
this.data.isopen = !this.data.isopen
}
})
.wxml
<button type="primary" bindtap="buttontap">{{state}}</button>
大概是這樣吧
.js
page({
data:{
isopen:true,
state:“開”
},
buttontap:function(){
if(this.data.isopen){
this.setData({
state:"關(guān)"
})
}else{
this.setData({
state:"開"
})
}
this.data.isopen = !this.data.isopen
}
})
.wxml
<button type="primary" bindtap="buttontap">{{state}}</button>