微信小程序官方組件展示之表單組件checkbox源碼

微信小程序官方組件展示之表單組件checkbox源碼

以下將展示微信小程序之表單組件checkbox源碼官方組件能力,組件樣式僅供參考,開發(fā)者可根據(jù)自身需求定義組件樣式,具體屬性參數(shù)詳見小程序開發(fā)文檔。

功能描述:

多選項(xiàng)目。

屬性說明:

示例代碼:

JAVASCRIPT

Page({

? onShareAppMessage() {

? ? return {

? ? ? title: 'checkbox',

? ? ? path: 'page/component/pages/checkbox/checkbox'

? ? }

? },

? data: {

? ? items: [

? ? ? {value: 'USA', name: '美國(guó)'},

? ? ? {value: 'CHN', name: '中國(guó)', checked: 'true'},

? ? ? {value: 'BRA', name: '巴西'},

? ? ? {value: 'JPN', name: '日本'},

? ? ? {value: 'ENG', name: '英國(guó)'},

? ? ? {value: 'FRA', name: '法國(guó)'}

? ? ]

? },

? checkboxChange(e) {

? ? console.log('checkbox發(fā)生change事件,攜帶value值為:', e.detail.value)

? ? const items = this.data.items

? ? const values = e.detail.value

? ? for (let i = 0, lenI = items.length; i < lenI; ++i) {

? ? ? items[i].checked = false

? ? ? for (let j = 0, lenJ = values.length; j < lenJ; ++j) {

? ? ? ? if (items[i].value === values[j]) {

? ? ? ? ? items[i].checked = true

? ? ? ? ? break

? ? ? ? }

? ? ? }

? ? }

? ? this.setData({

? ? ? items

? ? })

? }

})

WXML

<view class="container">

? <view class="page-body">

? ? <view class="page-section page-section-gap">

? ? ? <view class="page-section-title">默認(rèn)樣式</view>

? ? ? <label class="checkbox">

? ? ? ? <checkbox value="cb" checked="true"/>選中

? ? ? </label>

? ? ? <label class="checkbox">

? ? ? ? <checkbox value="cb" />未選中

? ? ? </label>

? ? </view>


? ? <view class="page-section">

? ? ? <view class="page-section-title">推薦展示樣式</view>

? ? ? <view class="weui-cells weui-cells_after-title">

? ? ? ? <checkbox-group bindchange="checkboxChange">

? ? ? ? ? <label class="weui-cell weui-check__label" wx:for="{{items}}" wx:key="{{item.value}}">

? ? ? ? ? ? <view class="weui-cell__hd">

? ? ? ? ? ? ? <checkbox value="{{item.value}}" checked="{{item.checked}}"/>

? ? ? ? ? ? </view>

? ? ? ? ? ? <view class="weui-cell__bd">{{item.name}}</view>

? ? ? ? ? </label>

? ? ? ? </checkbox-group>

? ? ? </view>

? ? </view>

? </view>


</view>


版權(quán)聲明:本站所有內(nèi)容均由互聯(lián)網(wǎng)收集整理、上傳,如涉及版權(quán)問題,請(qǐng)聯(lián)系我們第一時(shí)間處理。

原文鏈接地址:https://developers.weixin.qq.com/miniprogram/dev/component/checkbox.html

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容