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.代码部分

form表单,表单提交,formid_第1张图片

(1)wxml

 
switch slider input radio checkbox

(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

你可能感兴趣的:(微信小程序)