Home  >  Article  >  WeChat Applet  >  Interpretation and analysis of WeChat mini program components: introduction to checkbox options

Interpretation and analysis of WeChat mini program components: introduction to checkbox options

高洛峰
高洛峰Original
2017-03-19 17:32:042237browse

checkbox multiple optionsComponent description:


  • Checkbox is a component in the mini program form component. Its function is to guide users to make choices in the form.


  • To use the checkbox component, you also need to use the checkbox-group tag in addition to all checkbox tags in the same group.


  • The function of the checkbox-group label is to bind the onchange event to the checkbox label, and guide the user when the user makes a choice.


  • A single checkbox label will not trigger the onchange event, it will only be triggered if it is bound to the checkbox-group.


##checkbox optionComponentThe sample code runs as follows:

Interpretation and analysis of WeChat mini program components: introduction to checkbox options

##The following is the WXML code:

<view>
    <checkbox-group class="checkbox-group" bindchange="changed">
        <label class="items" wx:for="{{item}}">
            <checkbox value="{{item.value}}" checked="{{item.checked}}" disabled="{{item.disabled}}"/>
            {{item.name}}
        </label>
    </checkbox-group>
</view>



The following is the JS code:

Page({
  data:{
    item: [
      {&#39;name&#39;: &#39;俄罗斯&#39;, &#39;value&#39;: &#39;RS&#39;, &#39;disabled&#39;: false},
      {&#39;name&#39;: &#39;美国&#39;, &#39;value&#39;: &#39;US&#39;, &#39;disabled&#39;: false},
      {&#39;name&#39;: &#39;中国&#39;, &#39;value&#39;: &#39;CN&#39;, &#39;disabled&#39;: false, &#39;checked&#39;: true},
      {&#39;name&#39;: &#39;英国&#39;, &#39;value&#39;: &#39;UK&#39;, &#39;disabled&#39;: false},
      {&#39;name&#39;: &#39;日本&#39;, &#39;value&#39;: &#39;JP&#39;, &#39;disabled&#39;: true}
    ]
  },
  changed: function(e) {
    console.info(&#39;你选择了&#39; + e.detail.value);
  }
})


      The following is the WXSS code:
    .items {
        display: block;
        margin: 30rpx;
    }


of checkbox multiple options Main attributes:


#checkbox-group


##Attribute name

Data type

Description

##bindchange
EventHandle

Changes in the selected item trigger the change event, detail = {value:[array of value of the selected checkbox]}

##checkbox

##Attribute name

Data typeStringBooleandisabledBoolean

Description

Default value

value

identifier, triggers the change event of when selected, and carries the value of

#checked

Whether is selected by default

false

Whether is disabled

false

The above is the detailed content of Interpretation and analysis of WeChat mini program components: introduction to checkbox options. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn