微信小程序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
    })
  },
相关推荐
maosheng11462 小时前
RHCSA的第一次作业
linux·运维·服务器
恒创科技HK4 小时前
通用型云服务器与计算型云服务器:您真正需要哪些配置?
运维·服务器
源远流长jerry5 小时前
在 Ubuntu 22.04 上配置 Soft-RoCE 并运行 RDMA 测试程序
linux·服务器·网络·tcp/ip·ubuntu·架构·ip
twc8296 小时前
大模型生成 QA Pairs 提升 RAG 应用测试效率的实践
服务器·数据库·人工智能·windows·rag·大模型测试
土土哥V_araolin6 小时前
双迹美业模式系统开发(现成源码)
小程序·个人开发·零售
w-w0w-w7 小时前
Unix网络编程
服务器·网络·unix
肠胃炎8 小时前
挂载方式部署项目
服务器·前端·nginx
mldlds8 小时前
windows手动配置IP地址与DNS服务器以及netsh端口转发
服务器·windows·tcp/ip
一直都在5729 小时前
深入理解 synchronized:到底锁的是谁?
运维·服务器
RisunJan9 小时前
Linux命令-mkbootdisk(可建立目前系统的启动盘)
linux·运维·服务器