form表单,表单提交,formid

1.在使用提交表单时,尽量使用form表单,提交时有event参数,好多参数都可通过event.detail.value(此时,表单的各个元素需要添加name属性,否则这里会打印不到)来获取,比较方便,而且可以减少页面变量的使用,当然了,如果有些不能通过event来获取的话,还是得要用变量来储存的;

2.在有些时候可能还要用到formid,在form标签里添加report-submit='true'就可通过event.detail.formid来拿到,formid在模板消息中会用到

3.formid(模板消息,官方很详细,可以看一下)

官网:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/template-message.html

4.代码部分

(1)wxml

 <form bindsubmit="formSubmit" bindreset="formReset" report-submit='true'>
  <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>

(2)js

formSubmit: function (event) {
    console.log('event:', event)
    console.log('form发生了submit事件,携带数据为:', event.detail.value)
  },
  formReset: function () {
    console.log('form发生了reset事件')
  }

5.推荐

博客:https://blog.csdn.net/qq_38125123/article/details/74941492

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值