新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)小程序教程:微信小程序表單組件label
label

用來改進(jìn)表單組件的可用性,使用for屬性找到對(duì)應(yīng)的id,或者將控件放在該標(biāo)簽下,當(dāng)點(diǎn)擊時(shí),就會(huì)觸發(fā)對(duì)應(yīng)的控件。
for優(yōu)先級(jí)高于內(nèi)部控件,內(nèi)部有多個(gè)控件的時(shí)候默認(rèn)觸發(fā)第一個(gè)控件。
目前可以綁定的控件有:, , , 。
| 屬性名 | 類型 | 說明 |
|---|---|---|
| for | String | 綁定控件的id |
示例代碼:
表單組件在label內(nèi)
label用for標(biāo)識(shí)表單組件
Page({
data: {
checkboxItems: [
{name: 'USA', value: '美國(guó)'},
{name: 'CHN', value: '中國(guó)', checked: 'true'},
{name: 'BRA', value: '巴西'},
{name: 'JPN', value: '日本', checked: 'true'},
{name: 'ENG', value: '英國(guó)'},
{name: 'TUR', value: '法國(guó)'},
],
radioItems: [
{name: 'USA', value: '美國(guó)'},
{name: 'CHN', value: '中國(guó)', checked: 'true'},
{name: 'BRA', value: '巴西'},
{name: 'JPN', value: '日本'},
{name: 'ENG', value: '英國(guó)'},
{name: 'TUR', value: '法國(guó)'},
],
hidden: false
},
checkboxChange: function(e) {
var checked = e.detail.value
var changed = {}
for (var i = 0; i < this.data.checkboxItems.length; i ++) {
if (checked.indexOf(this.data.checkboxItems[i].name) !== -1) {
changed['checkboxItems['+i+'].checked'] = true
} else {
changed['checkboxItems['+i+'].checked'] = false
}
}
this.setData(changed)
},
radioChange: function(e) {
var checked = e.detail.value
var changed = {}
for (var i = 0; i < this.data.radioItems.length; i ++) {
if (checked.indexOf(this.data.radioItems[i].name) !== -1) {
changed['radioItems['+i+'].checked'] = true
} else {
changed['radioItems['+i+'].checked'] = false
}
}
this.setData(changed)
}
})
.label-1, .label-2{
margin-bottom: 15px;
}
.label-1__text, .label-2__text {
display: inline-block;
vertical-align: middle;
}
.label-1__icon {
position: relative;
margin-right: 10px;
display: inline-block;
vertical-align: middle;
width: 18px;
height: 18px;
background: #fcfff4;
}
.label-1__icon-checked {
position: absolute;
top: 3px;
left: 3px;
width: 12px;
height: 12px;
background: #1aad19;
}
.label-2__icon {
position: relative;
display: inline-block;
vertical-align: middle;
margin-right: 10px;
width: 18px;
height: 18px;
background: #fcfff4;
border-radius: 50px;
}
.label-2__icon-checked {
position: absolute;
left: 3px;
top: 3px;
width: 12px;
height: 12px;
background: #1aad19;
border-radius: 50%;
}
.label-4_text{
text-align: center;
margin-top: 15px;
}
本文標(biāo)題:創(chuàng)新互聯(lián)小程序教程:微信小程序表單組件label
URL鏈接:http://www.dlmjj.cn/article/dphscph.html


咨詢
建站咨詢
