This article introduces how to interpret and analyze the label labels of the mini-program component:
Label, which is basically the same as the label of html. The label element does not present any special effects to users. However, it improves availability for mouse users. If you click text in the label element, this control is triggered. That is to say, when you select this tag, the focus is automatically transferred to the form control bound to the tag, which is mainly used to improve the availability of the form component.
Use the for property to find the corresponding id, or place the control under the label. when you click it, the corresponding control is triggered.
The for priority is higher than the internal control. when multiple internal controls exist, the first control is triggered by default.
Currently, the following controls can be bound:, , ,
The sample code for component usage is as follows:
WXML code:
------- Label bind checkbox (embedded )-------
{Item. value }}
--------- Label bind radio ()---------
{Item. name }}
----------- Label: bind a button -----------
Label to bind button ()
Fly-1
Label bind button (embedded)
Fly-2
----------- Label binding switch -----------
Label binding switch ()
Label binding switch (embedded)
Label binding switch (embedded)
The JS code is as follows:
Page ({data: {checkboxItems: [{name: 'ctrip ', value: 'ctrip', checked: 'true'}, {name: 'qunar ', value: 'hangzhou'}, {name: 'tuniu', value: 'utniu '}], radioItems: [{name: 'ctrip', value: 'ctrip '}, {name: 'qunar', value: 'hangzhou', checked: 'true'}, {name: 'tuniu', value: 'topu'}], hidden: false}, checkboxChange: function (e) {var checked = e. detail. value var changed = {} for (var I = 0; I <this. data. checkboxItem S. length; I ++) {if (checked. indexOf (this. data. checkboxItems [I] [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. name )! =-1) {changed ['radioitems ['+ I +']. checked '] = true} else {changed ['radioitems [' + I + ']. checked '] = false} this. setData (changed)}, testLabelBindButton_1: function () {console. log ("Let's go! the button can be bound successfully through !!! ") ;}, TestLabelBindButton_2: function () {console. log (" Let's go! the button can be successfully bound through embedded !!! ");}})
The WXSS code is as follows:
.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: #CAE1FF;}.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: #CAFF70; border-radius: 50px;}.label-2__icon-checked { position: absolute; left: 3px; top: 3px; width: 12px; height: 12px; background: #1aad19; border-radius: 50%;}.section__title{ display: block; text-align: center; color: #9400D3;}.content{ padding-bottom: 15px;}
Main Attributes:
|
Attribute |
Type |
Type |
| For |
String |
Id of the bound control (the id is the same as the id of the form control to be bound) |
The preceding section describes how to interpret and analyze the instance by using the label of the applet component. For more information, see other related articles in the first PHP community!