W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
解釋:多項選擇器組,內(nèi)部由多個 checkbox 組成
屬性名 | 類型 | 默認(rèn)值 | 必填 | 說明 |
---|---|---|---|---|
bindchange | EventHandle | 否 |
|
代碼示例 1:默認(rèn)樣式
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">默認(rèn)樣式</view>
<label class="block border-bottom">
<checkbox checked>多選項一</checkbox>
</label>
<label class="block border-bottom">
<checkbox>多選項二</checkbox>
</label>
</view>
</view>
代碼示例 2:列表展示
<view class="wrap">
<view class="top-description border-bottom">列表展示</view>
<checkbox-group bindchange="checkboxChange">
<label class="block border-bottom" s-for="item in items">
<checkbox value="{{item.value}}" checked="{{item.checked}}">{{item.text}}</checkbox>
</label>
</checkbox-group>
</view>
Page({
data: {
items: [
{
text: '多選項一',
checked: true,
value: '1'
},
{
text: '多選項二',
value: '2'
},
{
text: '多選項三',
value: '3'
}
]
},
checkboxChange: e => {
console.log(e.detail);
}
});
代碼示例 3:包含禁用選項
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">
<view>包含禁用選項</view>
<view>disabled</view>
</view>
<label class="block border-bottom">
<checkbox value="checkbox1" checked>可用選項</checkbox>
</label>
<label class="block border-bottom">
<checkbox value="checkbox2">可用選項 </checkbox>
</label>
<label class="block border-bottom">
<checkbox value="checkbox3" disabled color="#C3D1FF" checked></checkbox>
<text class="disabledText">禁用選項</text>
</label>
<label class="block border-bottom">
<checkbox value="checkbox4" disabled color="#ccc"></checkbox>
<text class="disabledText">禁用選項</text>
</label>
</view>
</view>
Page({
checkboxChange: e => {
console.log(e.detail);
}
});
代碼示例 4:默認(rèn)不選中
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">
<view>默認(rèn)不選中</view>
<view>checked="false"</view>
</view>
<checkbox-group bindchange="checkboxChange" >
<label class="block border-bottom">
<checkbox value="checkbox1" checked>多選項一</checkbox>
</label>
<label class="block border-bottom">
<checkbox value="checkbox2">多選項二</checkbox>
</label>
</checkbox-group>
</view>
</view>
Page({
checkboxChange: e => {
console.log(e.detail);
}
});
代碼示例 5:自定義顏色
<view class="wrap">
<view class="card-area">
<view class="top-description border-bottom">
<view>自定義顏色</view>
<view>color="#00BC89"</view>
</view>
<checkbox-group bindchange="checkboxChange" >
<label class="block border-bottom">
<checkbox value="checkbox1" color="#00BC89" checked>選項名稱</checkbox>
</label>
<label class="block border-bottom">
<checkbox value="checkbox2" color="#00BC89">選項名稱</checkbox>
</label>
</checkbox-group>
</view>
</view>
Page({
checkboxChange: e => {
console.log(e.detail);
}
});
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: