Home  >  Article  >  Web Front-end  >  How to use switch selector in WeChat applet

How to use switch selector in WeChat applet

亚连
亚连Original
2018-06-08 16:28:353011browse

This article mainly introduces the use of the switch selector of the WeChat applet in detail. It has certain reference value. Interested friends can refer to it.

This article shares with you the WeChat applet switch selector. How to use the program switch switch selector is for your reference. The specific content is as follows

Rendering

How to use switch selector in WeChat applet

##WXML

<view class="tui-list-box">
 <view class="tui-menu-list">
  <text>状态:{{isChecked1}}</text>
  <switch class="tui-fr" checked="{{isChecked1}}" bindchange="changeSwitch1"/>
 </view>
 <view class="tui-menu-list">
  <text>状态:{{isChecked2}}</text>
  <switch class="tui-fr" checked="{{isChecked2}}" bindchange="changeSwitch2"/>
 </view>
 <view class="tui-menu-list">
  <text>状态:{{isChecked3}}</text>
  <switch class="tui-fr" color="#007aff" checked="{{isChecked3}}" bindchange="changeSwitch3"/>
 </view>
 <view class="tui-menu-list">
  <text>状态:{{isChecked4}}</text>
  <switch class="tui-fr" color="#007aff" checked="{{isChecked4}}" bindchange="changeSwitch4"/>
 </view>
 <view class="tui-menu-list">
  <text>状态:{{isChecked5}}</text>
  <switch class="tui-fr" type="checkbox" checked="{{isChecked5}}" bindchange="changeSwitch5"/>
 </view>
 <view class="tui-menu-list">
  <text>状态:{{isChecked6}}</text>
  <switch class="tui-fr" type="checkbox" checked="{{isChecked6}}" bindchange="changeSwitch6"/>
 </view>
</view>

JS

var pageObj = {
 data: {
  isChecked1: false,
  isChecked2: true,
  isChecked3: false,
  isChecked4: true,
  isChecked5: false,
  isChecked6: true
 }
};

for (var i = 0; i < 7; ++i) {
 (function (i) {
  pageObj[&#39;changeSwitch&#39; + i] = function (e) {
   var changedData = {};
   changedData[&#39;isChecked&#39; + i] = !this.data[&#39;isChecked&#39; + i];
   this.setData(changedData);
  }
 })(i)
}
Page(pageObj);

Attributes of the switch component

  • checked: Whether to check—false, true

  • type: The style of the switch selector—- switch, checkbox

  • color: The color of switch, the same as the color of css

The above is what I compiled for everyone, I hope it will be helpful to everyone in the future helpful.

Related articles:

How to implement offset and uniform animation in JS

How to implement table merge cells in Bootstrap

How to get the first value in the select drop-down box in JavaScript

The above is the detailed content of How to use switch selector in WeChat applet. 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