Home  >  Article  >  WeChat Applet  >  WeChat applet uses checkbox to display multiple selection box function [source code attached]

WeChat applet uses checkbox to display multiple selection box function [source code attached]

不言
不言Original
2018-06-22 17:26:585548browse

This article mainly introduces the function of using checkbox to display multiple selection boxes in WeChat applet, involving related event binding and element traversal operation techniques, and comes with source code for readers to download and refer to. Friends in need can refer to it

The example in this article describes the WeChat applet's use of checkbox to display multiple selection boxes. Share it with everyone for your reference, the details are as follows:

1. Effect display

##2. Key code

① index.wxml

<checkbox-group bindchange="checkboxgroupBindchange">
 <checkbox value="checkbox1">checkbox1</checkbox>
 <checkbox value="checkbox2">checkbox2</checkbox>
 <checkbox value="checkbox3">checkbox3</checkbox>
</checkbox-group>
<view>提示:{{text}}</view>

② index.js

Page({
 data:{
  // text:"这是一个页面"
  text:&#39;&#39;
 },
 checkboxgroupBindchange:function(e){
  var temp1=e.detail.value
  var temp2=&#39;&#39;
  console.log(temp1)
  if(temp1.length!=0){
   for(var i=0,len=temp1.length;i<len;i++){
    temp2=temp2+temp1[i]+&#39;,&#39;
   }
   this.setData({
    text:&#39;您选择了:&#39;+temp2
   })
  }else{
   this.setData({
    text:&#39;&#39;
   })
  }
 }
})

3. Source code

For detailed usage instructions of the checkbox component, please refer to the official website:

https://mp.weixin.qq.com/debug/wxadoc/dev/component/checkbox.html

The above is the entire content of this article. I hope it will be useful for everyone’s learning. For help, please pay attention to the PHP Chinese website for more related content!

Related recommendations:

WeChat applet uses radio to display single option function [source code attached]

The above is the detailed content of WeChat applet uses checkbox to display multiple selection box function [source code attached]. 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