表单(form),用于提交组件内用户输入的 <textarea>、<switch/>、<input/>、<checkbox-group/>、<slider/>、<radio-group/>、<picker/> 等组件。
当单击 form 表单中 form-type 为 submit 的 button 组件时,会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key。
| 属性名 | 类型 | 默认值 | 描述 | 最低版本 |
|---|---|---|---|---|
| onSubmit | EventHandle | - | 携带 form 中的数据触发 submit 事件。event.detail = {value : {'name': 'dao14'}, buttonTarget: {'dataset': 'buttonDataset'} } |
buttonTarget 1.7.0 开始支持 |
| onReset | EventHandle | - | 表单重置时会触发 reset 事件。 |
- |
图示

代码示例
<form onSubmit="formSubmit" onReset="formReset"><view class="section section_gap"><view class="section__title">switch</view><switch name="switch"/></view><view class="section section_gap"><view class="section__title">slider</view><slider name="slider" show-value ></slider></view><view class="section"><view class="section__title">input</view><input name="input" placeholder="please input here" /></view><view class="section section_gap"><view class="section__title">radio</view><radio-group name="radio-group"><label><radio value="radio1"/>radio1</label><label><radio value="radio2"/>radio2</label></radio-group></view><view class="section section_gap"><view class="section__title">checkbox</view><checkbox-group name="checkbox"><label><checkbox value="checkbox1"/>checkbox1</label><label><checkbox value="checkbox2"/>checkbox2</label></checkbox-group></view><view class="btn-area"><button formType="submit">Submit</button><button formType="reset">Reset</button></view></form>
Page({formSubmit: function(e) {console.log('form发生了submit事件,携带数据为:', e.detail.value)},formReset: function() {console.log('form发生了reset事件')}})
该文章对您有帮助吗?