WeChat Open Platform

Mini Programs Documentation

switch

Switch selector

Attribute name Type Default value Description
checked Boolean false Whether selected
type String switch Style, valid values: switch, checkbox
bindchange EventHandle A change event triggered when checked changes, event.detail={ value:checked}
color Color switch color, same as css color
<view class="body-view">
    <switch checked bindchange="switch1Change"/>
    <switch bindchange="switch2Change"/>
</view>
Page({
  switch1Change: function (e){
    console.log('switch1 has experienced a change event, the value brought is', e.detail.value)
  },
  switch2Change: function (e){
    console.log('switch2 has experienced a change event, the value brought is', e.detail.value)
  }
})

switch