小程序自定义radio和点击取反,例如默认是,点击否,再点击是

步骤一

在data初始数据定义isopen:true
在这里插入图片描述

步骤二

// 小程序自定义radio
onsChange() {
var that = this
this.setData({
//取反
isopen: !that.data.isopen
})
console.log(that.data.isopen)
},
默认为不选中
在这里插入图片描述
点击选中
在这里插入图片描述
wxml页面用的三元表达式




复制只需换下你们的图片就可以用

例如默认true,点击false,再点击true

步骤一

在data初始数据定义change:true,
changbtn:‘可爱’

在这里插入图片描述

步骤二

changbtn(){
if (this.data.change==true){
this.setData({
changbtn:‘可爱’
})
}else{
this.setData({
changbtn: ‘你不可爱’
})
}
//取反
this.data.change = !this.data.change
},
wxml页面

{ {changbtn}}

默认
在这里插入图片描述
再点击在这里插入图片描述

总结:上面那两种方法都是利用的取反。

猜你喜欢

转载自blog.csdn.net/weixin_46012140/article/details/104582422
今日推荐