当前位置:网站首页>【微信小程序:单选、多选样式,背景色,圆角】
【微信小程序:单选、多选样式,背景色,圆角】
2022-06-30 06:07:00 【常安cc】
【微信小程序:单选、多选样式,背景色,圆角】
单选

<!-- 个性服务 -->
<view class="addrBox-item">
<view class="addr-head">
<image src="/image/leftIcon.png" class="leftIconImg"></image>
<view class="item-title">个性服务</view>
</view>
<!-- -->
<view class="addr-box">
<!-- <radio checked='{
{check}}' id="radios" bindtap='radiocon'></radio> <label for="radios">匿名</label> -->
<!-- <view wx:for="{
{authData}}" wx:key="index" class="addr-item {
{item.selected?'selectedItem':''}}" data-index='{
{index}}' catchtap="checkboxChange">{
{item.title}}</view> -->
<radio-group bindchange="radioChange" class="radio_group">
<label class="check_label" wx:for="{
{radios}}" wx:key="index">
<view class="radioBox">
<radio value="{
{item.value}}" />
<view class="radionName">{
{item.name}}</view>
</view>
</label>
</radio-group>
</view>
</view>
// 单选
radios: [{
value: 'aa',
name: '支持贴牌',
// checked: 'true'
},
{
value: 'bb',
name: '一件代发'
},
]
// 单选框
radioChange(e) {
console.log('radio发生change事件,携带value值为:', e.detail.value)
const radios = this.data.radios;
for (let i = 0; i < radios.length; ++i) {
radios[i].checked = radios[i].value === e.detail.value
}
this.setData({
radios
})
},
/* 单选框样式 */
/* 初始样式 */
radio .wx-radio-input {
width: 32rpx;
height: 32rpx;
border-radius: 50%;
}
/* 选中后的 背景样式 ( 背景 边框 ) */
radio .wx-radio-input.wx-radio-input-checked {
/* 选中后对勾大小,不要超过背景的尺寸 */
width: 32rpx;
height: 32rpx;
background: #ff3b3b !important;
border-radius: 50%;
border: 1px solid #ff3b3b !important;
}
/* 选中后的 对勾样式 */
radio .wx-radio-input.wx-radio-input-checked::before {
/* 选中后对勾大小,不要超过背景的尺寸 */
width: 32rpx;
height: 32rpx;
line-height: 32rpx;
text-align: center;
font-size: 28rpx;
/* 对勾大小 */
font-weight: 400;
color: #fff;
/* 对勾颜色 */
background: #ff3b3b !important;
border-radius: 50%;
border: 1px solid #ff3b3b !important;
transform: translate(-50%, -50%) scale(1);
-webkit-transform: translate(-50%, -50%) scale(1);
}
.radio_group {
display: flex;
}
.check_label {
display: flex;
align-items: center;
margin-right: 40rpx;
}
.radioBox {
display: flex;
}
.radionName {
margin-left: 4rpx;
}
多选

<!-- 个性服务 -->
<view class="addrBox-item">
<view class="addr-head">
<image src="/image/leftIcon.png" class="leftIconImg"></image>
<view class="item-title">个性服务</view>
</view>
<!-- -->
<view class="addr-box">
<checkbox-group bindchange="Check" class="radio_group">
<label class="check_label" wx:for="{
{checkData}}" wx:key="index">
<view class="radioBox">
<checkbox value="{
{item.value}}" checked="{
{item.checked}}" />
</view>
<view class="radionName">{
{item.name}}</view>
</label>
</checkbox-group>
</view>
</view>
/* 单选框样式 */
/* 初始样式 */
checkbox .wx-checkbox-input {
width: 32rpx;
height: 32rpx;
border-radius: 50%;
}
/* 选中后的 背景样式 ( 背景 边框 ) */
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
/* 选中后对勾大小,不要超过背景的尺寸 */
width: 32rpx;
height: 32rpx;
background: #ff3b3b !important;
border-radius: 50%;
border: 1px solid #ff3b3b !important;
}
/* 选中后的 对勾样式 */
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
/* 选中后对勾大小,不要超过背景的尺寸 */
width: 32rpx;
height: 32rpx;
line-height: 32rpx;
text-align: center;
font-size: 28rpx;
/* 对勾大小 */
font-weight: 400;
color: #fff;
/* 对勾颜色 */
background: #ff3b3b !important;
border-radius: 50%;
border: 1px solid #ff3b3b !important;
transform: translate(-50%, -50%) scale(1);
-webkit-transform: translate(-50%, -50%) scale(1);
}
// 多选
checkData: [{
value: 'isOem',
name: '支持贴牌',
// checked: 'true'
},
{
value: 'isDropShipping',
name: '一件代发'
}
],
},
// 多选
Check(e) {
console.log('checkbox发生change事件,携带value值为:', e.detail.value)
const checkData = this.data.checkData;
const values = e.detail.value;
for (let i = 0, lenI = checkData.length; i < lenI; ++i) {
checkData[i].checked = false;
for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
if (checkData[i].value === values[j]) {
checkData[i].checked = true;
break;
}
}
}
this.setData({
checkData
})
console.log(this.data.checkData);
if (this.data.checkData[0].checked) {
console.log(this.data.checkData[0].checked, '选中');
} else {
}
},
边栏推荐
- Inno setup the simplest user-defined interface effect
- 拼多多店铺搜索相关问题,为什么新品上架搜索不到
- Variable parameters of go
- File operation io-part1
- [road of system analyst] collection of wrong topics in Project Management Chapter
- 关于Glide加载图片模糊不清楚
- Es6数组
- C language code record
- Summation of basic exercise sequence of test questions
- [regular expression series] greedy and non greedy patterns
猜你喜欢

Dao -- a beautiful new world?

飞升:基于中文分词器IK-2种自定义热词分词器构建方式showcase & 排坑showtime

SparseArray

Finally someone can make the server so straightforward

After getting these performance test decomposition operations, your test path will be more smooth

Tornado frame foundation

Mysql database learning notes - foreign keys, table connections, subqueries, and indexes for MySQL multi table queries

Projet Web de déploiement du serveur Cloud

What indicators should safety service engineers pay attention to in emergency response?

Here comes the nearest chance to Ali
随机推荐
[Alibaba cloud] student growth plan answers
接口中方法详解
How to print pthread_ t - How to print pthread_ t
leetcode763. Divide letter interval
Feisheng: Based on the Chinese word breaker ik-2 ways to build custom hot word separators Showcase & pit arrangement Showtime
ES6扩展运算符(...)
Implementation of property management system with ssm+ wechat applet
Who doesn't want a blog site of their own - build a blog site WordPress
Mariadb数据库的安装与初始化
反编译正常回编译出现问题自己解决办法
10-【istio】istio Sidecar
Application of redis client list in practice
ES6 array
观察者模式、状态模式在实际工作中的使用
Tornado frame foundation
[regular expression series] greedy and non greedy patterns
【学习强化学习】总目录
Summation of basic exercise sequence of test questions
ES6 extended operator (...)
583. 两个字符串的删除操作-动态规划