All Products
Search
Document Center

label

Last Updated: Apr 19, 2021

You can use label to improve the usability of form components. Use the for attribute to find the id of the corresponding component, or place the component under this label. When you click the label, the corresponding component is focused.

for has a higher priority than internal components. When multiple internal components exist, the first component is triggered by default.

Currently, you can bind the following controls: <checkbox/>, <radio/>, <input/>, and <textarea/>.

Attribute Type Description Minimum version
for String The ID of the bound component. -

Illustration

Code sample

  1. <view class="section">
  2. <view class="title">Checkbox, which is the checkbox nested in the label.</view>
  3. <checkbox-group>
  4. <view>
  5. <label>
  6. <checkbox value="aaa" />
  7. <text>aaa</text>
  8. </label>
  9. </view>
  10. <view>
  11. <label>
  12. <checkbox value="bbb" />
  13. <text>bbb</text>
  14. </label>
  15. </view>
  16. </checkbox-group>
  17. </view>
  18. </view>
  19. <view class="section">
  20. <view class="title">Radio, which is associated by for.</view>
  21. <radio-group>
  22. <view>
  23. <radio id="aaa" value="aaa" />
  24. <label for="aaa">aaa</label>
  25. </view>
  26. <view>
  27. <radio id="bbb" value="bbb" />
  28. <label for="bbb">bbb</label>
  29. </view>
  30. </radio-group>
  31. </view>
  32. </view>
  33. <view class="section">
  34. <view class="title">When multiple Checkbox items are clicked, only one of them is selected.</view>
  35. <label>
  36. <checkbox>Select me</checkbox>
  37. <checkbox>Do not select</checkbox>
  38. <checkbox>Do not select</checkbox>
  39. <checkbox>Do not select</checkbox>
  40. <view>
  41. <text>Click Me</text>
  42. </view>
  43. </label>
  44. </view>
  45. </view>