微信小程序如何修改radio和checkbox的默認(rèn)樣式和圖標(biāo)
wxml:
<view class="body">
<view class="body-content">
第1題:企業(yè)的價(jià)值觀是 ?
</view>
<view class="label">單選</view>
</view>
<view class="options">
<radio-group class="radio-group" bindchange="radioChange">
<label class="radio" wx:for="{{items}}" wx:key="{{index}}">
<view>
<radio value="{{item.name}}" checked="{{item.checked}}"/>{{item.value}}
</view>
</label>
</radio-group>
</view>
我們看一下原生的效果:

修改wxml中的redio 組件的color屬性:
<radio value="{{item.name}}" checked="{{item.checked}}" color="#fff"/>{{item.value}}
wxss(只有修改樣式的部分):
/* 單選、多選 勾選 */
/*radio未選中時(shí)樣式 */
radio .wx-radio-input{
/* 自定義樣式.... */
/* 我這里沒有進(jìn)行,未選中的樣式修改
height: 40rpx;
width: 40rpx;
margin-top: -4rpx;
border-radius: 50%;
border: 2rpx solid #999;
background: transparent;
*/
}
/* 選中后的 背景樣式 (紅色背景 無邊框 可根據(jù)UI需求自己修改) */
radio .wx-radio-input.wx-radio-input-checked {
/* border: none; */
border-color: #2792ff!important;
/* background-color: #fff!important; */
/* background-color: transparent!important; */
/* 居中 */
/*
display: flex;
justify-content: center;
align-items: center;
*/
}
/* 選中后的 對(duì)勾樣式 (白色對(duì)勾 可根據(jù)UI需求自己修改) */
radio .wx-radio-input.wx-radio-input-checked::before {
/* 去除對(duì)號(hào) */
content: '';
/* background: #fff; */
width: 36rpx;
height: 36rpx;
border-radius: 50%;
/* background: red; */
background-color: #2792ff;
/* 居中 */
/* margin-top: 0rpx; */
/* display: flex; */
/* position: relative; */
}
修改后的單選框樣式:

復(fù)選框同理
wxml:
<view class="body">
<view class="body-content">
第1題:企業(yè)的價(jià)值觀是 ?
</view>
<view class="label">多選</view>
</view>
<view class="options">
<checkbox-group bindchange="checkboxChange">
<label class="checkbox" wx:for="{{items}}">
<view>
<checkbox value="{{item.name}}" checked="{{item.checked}}"/>{{item.value}}
</view>
</label>
</checkbox-group>
</view>
wxss:
/*checkbox未選中時(shí)樣式 */
checkbox .wx-checkbox-input{
/* 自定義樣式.... */
border-radius: 50%;
}
/* 選中后的 背景樣式 (紅色背景 無邊框 可根據(jù)UI需求自己修改) */
checkbox .wx-checkbox-input.wx-checkbox-input-checked {
/* border: none; */
border-radius: 50%;
border-color: #2792ff!important;
}
/* 選中后的 對(duì)勾樣式 (白色對(duì)勾 可根據(jù)UI需求自己修改) */
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
/* 去除對(duì)號(hào) */
content: '';
/* background: #fff; */
width: 36rpx;
height: 36rpx;
border-radius: 50%;
/* background: red; */
background-color: #2792ff;
/* 居中 */
/* margin-top: 0rpx; */
/* display: flex; */
/* position: relative; */
}
修改前后對(duì)比:
前

后

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
js中eval方法詳解之eval方法的初級(jí)應(yīng)用
js中eval()函數(shù)可計(jì)算某個(gè)字符串,下面這篇文章主要給大家介紹了關(guān)于js中eval方法詳解之eval方法的初級(jí)應(yīng)用的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-01-01
JS實(shí)現(xiàn)頁(yè)面長(zhǎng)時(shí)間不操作退出到登錄頁(yè)面的示例代碼
這篇文章主要介紹了JS實(shí)現(xiàn)頁(yè)面長(zhǎng)時(shí)間不操作退出到登錄頁(yè)面的示例代碼,通過在head標(biāo)簽中引入jquey和頁(yè)面長(zhǎng)時(shí)間不操作的js頁(yè)面,結(jié)合實(shí)例代碼講解的非常詳細(xì),需要的朋友可以參考下2024-03-03
JavaScript實(shí)現(xiàn)計(jì)算字符串中出現(xiàn)次數(shù)最多的字符和出現(xiàn)的次數(shù)
這篇文章主要介紹了JavaScript實(shí)現(xiàn)計(jì)算字符串中出現(xiàn)次數(shù)最多的字符和出現(xiàn)的次數(shù),本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-03-03
plupload+artdialog實(shí)現(xiàn)多平臺(tái)上傳文件
這篇文章主要介紹了plupload+artdialog實(shí)現(xiàn)多平臺(tái)上傳文件的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07

