微信小程序开发 专题
专题目录
您的位置:微信小程序开发 > 微信小程序开发专题 > 微信小程序表单组件 form
微信小程序表单组件 form
作者:--    发布时间:2019-11-20

表单,将组件内的用户输入的<switch/> <input/> <checkbox/> <slider/> <radio/> <picker/> 提交。

当点击<form/>表单中 formtype 为 submit 的<button/>组件时,会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key。

属性名 类型 说明
report-submit boolean 是否返回formid用于发送模板消息
bindsubmit eventhandle 携带form中的数据触发submit事件,event.detail = { value : {"name":"value"} , formid:"" }
bindreset eventhandle 表单重置时会触发reset事件

示例代码:

<form bindsubmit="formsubmit" bindreset="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事件')
  }
})

form

网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册