Home > Article > WeChat Applet > Example of how a small program can dynamically control the opening and closing of a switch
Requirements:
In the process of developing small programs, we may encounter some switch control functions, such as whether to subscribe or whether to turn on 4G. At this time we need to set up a switch page. Today we are going to introduce how the small program can dynamically control the opening and closing of the switch
Part of the code
Home page code As follows:
<view class="copyright"> <view class="copyright_item">CopyRight:All Right Reserved</view> <view class="copyright_item">原创作者:HTML51.COM</view> <view class="copyright_item">微信小程序开发平台:51小程序</view> <view class="copyright_item"><image class="img" src="../copyright/image/logo.png"/></view> <view class="goto_counter"><button type="default" bindtap="goto_counter">点击进去控制switch的开和闭</button></view> </view>
index.wxml code is as follows:
<switch checked="{{switchChecked}}"/> <button type="default" bindtap="openSwitch">打开开关</button> <button type="default" bindtap="closeSwitch">关闭开关</button> <switch checked="{{switchChecked}}"/> <button type="default" bindtap="openSwitch">打开开关</button> <button type="default" bindtap="closeSwitch">关闭开关</button>
For more examples of how small programs can dynamically control the opening and closing of switch switches, please pay attention to the PHP Chinese website for related articles!