switch

解释: 开关选择器

属性名类型默认值说明
checkedBooleanfalse是否选中
typeStringswitch样式,有效值:switch,checkbox
colorColor#09bb07switch 的颜色,同 CSS 的 color
disabledBooleanfalse是否禁用
bindchangeEventHandle-checked 改变时触发 change 事件,event.detail={ checked:true}

示例在开发者工具中预览效果

  1. <!-- swith.swan -->
    <form bind:submit="formSubmit">
    <switch name="switch1" type="checkbox" checked="false"></switch>
    <switch name="switch2" color="red"></switch>
    <switch name="switch3" checked></switch>
    <switch name="switch4" checked="true"></switch>
    <switch name="switch5" bind:change="changeEvent"></switch>
    <button formType="submit">提交</button>
    <button formType="reset">重置</button>
    </form>

  1. // switch.js
    changeEvent: e ={
    console.log('change', e);
    },
    formSubmit: e ={
    console.log('submit', e);
    }

说明:switch 类型切换时在 IOS 自带振动反馈,可在系统设置 -声音与触感 -系统触感反馈中关闭。