JS clear the form after submitting the form

Empty form is more common scenario, the form itself is reset events acting on empty forms, but need to click the reset button to trigger the event, we do not want to touch of a button within the submit event of the form submitted when the form is submitted successfully clear the form in value.

Let's look at the code, very simple

In small micro-channel for the Sample

<!--index.wxml-->
<form class='form' bindsubmit='formSubmit' bindreset='formReset'>
  <input name='name' value='{{name}}' placeholder='请输入姓名'></input>
  <input name='phone' value='{{phone}}' placeholder='请输入电话'></input>
  <input name='gender' value='{{gender}}' placeholder='请输入性别'></input>
  <input name='age' value='{{age}}' placeholder='请输入年龄'></input>
  <button bindtap="sendMessage" type='primary' formType="submit">开始</button>
</form>

js

  formSubmit(e){
    console.log(e)
    for (var i in e.detail.value){
      this.setData({
        [i]:''
      })
    }
  },

Renderings
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/qq_42363090/article/details/93464309