⼩程序如何实现radio单选框单击打勾和取消前端使⽤input 来写radio,⼩程序使⽤radio标签也可以使⽤<radio />单标签
1.⾃定义radio样式、
wx默认的是真的丑
/* 单选框样式 */
/* 初始样式 */
radio .wx-radio-input{
width: 32rpx;
height: 32rpx;
border-radius: 0
}
/* 选中后的背景样式(背景边框) */
radio .wx-radio-input.wx-radio-input-checked{
width: 32rpx; /* 选中后对勾⼤⼩,不要超过背景的尺⼨ */
height: 32rpx; /* 选中后对勾⼤⼩,不要超过背景的尺⼨ */
background:white!important;
}
/* 选中后的对勾样式  */htmlradio的text出不来
radio .wx-radio-input.wx-radio-input-checked::before{
width: 32rpx; /* 选中后对勾⼤⼩,不要超过背景的尺⼨ */
height: 32rpx; /* 选中后对勾⼤⼩,不要超过背景的尺⼨ */
line-height: 32rpx;
text-align: center;
font-size:36rpx; /* 对勾⼤⼩ */
color:black; /* 对勾颜⾊  */
background: white;
transform:translate(-50%, -50%) scale(1);
-webkit-transform:translate(-50%, -50%) scale(1);
}
2.单选打勾再选打勾取消效果
wxml:
<radio checked='{{check}}' id="radios" bindtap='radiocon'></radio><label for="radios">匿名</label>
wx.js
//这条代码在data⾥写
check:false
radiocon:function(e){
this.setData({
check: !this.data.check
})
console.log("⽤户打勾的是 ",this.data.check)
},
这样就完成了单击打勾再击取消。
以上。