目录

checkbox

Represents the checkbox.

Since: 1.0.0

Attributes

Name Type Default Value Mandatory Description
value string - No Component value. Checking it triggers the change event of checkbox-group and passes value of checkbox.
disabled boolean false No Whether the component is disabled.
checked boolean false No Whether the component is selected. You can set the checkbox to be selected by default.
color string #0A59F7 No Color of the checkbox, which follows the CSS color value syntax.

Example

HXML file:

<view class="page-body">
  <checkbox-group bindchange="checkboxChange">
  <label class="checkbox" has:for="{{ items }}">
    <checkbox
      value="{{ item.name }}"
      checked="{{ item.checked }}"
      disabled="{{ item.disabled }}"/>
    {{item.value}}
  </label>
  </checkbox-group>
</view>

JavaScript file:

Page({
  data: {
    items: [
      { name: 'angular', value: 'AngularJS' },
      { name: 'react', value: 'React' },
      { name: 'vue', value: 'Vue.js', checked: true },
      { name: 'node', value: 'nodejs' },
      { name: 'element', value: 'element-ui', disabled: true },
    ],
  },
  checkboxChange: function(e) {
    console.info('A change event occurred in the checkbox. Carried value: ', e.detail.value);
  }
});