以下將展示微信小程序之表單組件radio源碼官方組件能力,組件樣式僅供參考,開發(fā)者可根據(jù)自身需求定義組件樣式,具體屬性參數(shù)詳見小程序開發(fā)文檔。
功能描述:
單選項(xiàng)目。
Bug& Tip
1.tip:若當(dāng)前組件所在的頁面或全局開啟了 enablePassiveEvent 配置項(xiàng),該內(nèi)置組件可能會出現(xiàn)非預(yù)期表現(xiàn)(詳情參考enablePassiveEvent 文檔)
屬性說明:

示例代碼
JAVASCRIPT:
Page({
? onShareAppMessage() {
? ? return {
? ? ? title: 'radio',
? ? ? path: 'page/component/pages/radio/radio'
? ? }
? },
? data: {
? ? items: [
? ? ? {value: 'CHN', name: '中國', checked: 'true'},
? ? ? {value: 'BRA', name: '巴西'},
? ? ? {value: 'ENG', name: '英國'},
? ? ? {value: 'FRA', name: '法國'},
? ? ]
? },
? radioChange(e) {
? ? console.log('radio發(fā)生change事件,攜帶value值為:', e.detail.value)
? ? const items = this.data.items
? ? for (let i = 0, len = items.length; i < len; ++i) {
? ? ? items[i].checked = items[i].value === e.detail.value
? ? }
? ? this.setData({
? ? ? items
? ? })
? }
})
WXML:
<view class="page-body">
? <view class="page-section">
? ? <view class="page-section-title">默認(rèn)樣式</view>
? ? <label class="radio">
? ? ? <radio value="r1" checked="true"/>選中
? ? </label>
? ? <label class="radio">
? ? ? <radio value="r2" />未選中
? ? </label>
? </view>
? <view class="page-section">
? ? <view class="page-section-title">推薦展示樣式</view>
? ? <view class="weui-cells weui-cells_after-title">
? ? ? <radio-group bindchange="radioChange">
? ? ? ? <label class="weui-cell weui-check__label" wx:for="{{items}}" wx:key="{{item.value}}">
? ? ? ? ? <view class="weui-cell__hd">
? ? ? ? ? ? <radio value="{{item.value}}" checked="true"/>
? ? ? ? ? </view>
? ? ? ? ? <view class="weui-cell__bd">{{item.name}}</view>
? ? ? ? </label>
? ? ? </radio-group>
? ? </view>
? </view>
</view>

版權(quán)聲明:本站所有內(nèi)容均由互聯(lián)網(wǎng)收集整理、上傳,如涉及版權(quán)問題,請聯(lián)系我們第一時(shí)間處理。
原文鏈接地址:https://developers.weixin.qq.com/miniprogram/dev/component/radio.html