// wxml
<picker bindchange="bindChange" value="{{index}}" range="{{array}}">
当前选择:{{array[index]}}
</picker>
// js
Page({
data: {
array: ['美国', '中国', '巴西'],
index: 0
},
bindPickerChange: function(e) {
console.log('picker 值为:', e.detail.value)
this.setData({
index: e.detail.value
})
}
})
<checkbox-group>
中包含多项<checkbox>
<checkbox-group>
<checkbox value="" checked=""/>name
...
</checkbox-group>
<checkbox-group>
中可以绑定change
事件
// wxml
<checkbox-group bindchange="checkboxChange">
...
</checkbox-group>
// js
checkboxChange: function(e) {
console.log('value:', e.detail.value)
}
<slider bindchange="sliderchange" step="5" min="50" max="200" show-value/>
sliderchange:function(e) {
console.log('slider 值为', e.detail.value)
}
<switch checked="{{isChecked}}" bindchange="switchChange"/>
switchChange: function (e){
console.log('switch值为', e.detail.value)
}
使用form
组件,其中放入各类表单组件,然后使用submit
类型的button
触发提交事件,处理函数中可以得到所有的表单数据
// wxml
<form bindsubmit="formSubmit">
<switch name="switch"/>
<slider name="slider"></slider>
<button formType="submit">Submit</button>
</form>
// js
formSubmit: function(e) {
console.log('提交的所有数据:', e.detail.value)
}