微信小程序radio单选按钮选中与取消

wxml

复制代码
<view bindtap='checkedTap'>
      <radio checked="{{checked}}">设为默认</radio>
</view>

wxss

复制代码
<style lang="less" >
radio .wx-radio-input {
  border-radius: 50%; /* 圆角 */
  width: 24rpx;
  border: 2rpx solid #5e5e5f;
  height: 24rpx;
}
radio .wx-radio-input.wx-radio-input-checked {
  border: none;
  background: #c1885a;
}
radio .wx-radio-input.wx-radio-input-checked::before {
  border-radius: 50%; /* 圆角 */
  width: 28rpx; /* 选中后对勾大小,不要超过背景的尺寸 */
  height: 28rpx; /* 选中后对勾大小,不要超过背景的尺寸 */
  line-height: 28rpx;
  text-align: center;
  font-size: 20rpx; /* 对勾大小 30rpx */
  color: #fff; /* 对勾颜色 白色 */
  background: #c1885a;
  transform: translate(-50%, -50%) scale(1);
}
</style>

在点击事件中,通过取反即可实现选中与取消。

js

复制代码
 data: {
    checked:true
  },
  //是否选中
  checkedTap: function () {
    this.setData({
      "checked": !this.data.checked
    })
  },
相关推荐
节点小宝12 分钟前
节点小宝与中兴路由合作升级:AX5400系列新增远程控网功能
服务器·网络·安全·智能路由器·远程工作
无敌的牛1 小时前
Linux操作系统
linux·运维·服务器
Biomamba生信基地2 小时前
Linux| 二.计算机软件组成与Linux
linux·运维·服务器·生信·医药
Hero_11273 小时前
在pycharm中install不上需要的包
服务器·前端·pycharm
胜天半月子3 小时前
Python自动化测试 | 快速认识并了解pytest的基本使用
服务器·python·pytest
xflySnail4 小时前
内网穿透方案-nps
linux·服务器·内网穿透·nps
QiTinna4 小时前
Linux运维核心命令(入门)
linux·运维·服务器
初听于你4 小时前
LoRa与ZigBee:物联网双雄对决
服务器·网络·windows·网络协议·计算机网络
weixin_177297220696 小时前
旧物二手回收小程序:引领绿色消费,开启时尚生活新方式
小程序·盲盒
0wioiw06 小时前
Ubuntu(③vsftpd)
linux·服务器·ubuntu