微信小程序 清空input框内容

版权声明: https://blog.csdn.net/qq_23521659/article/details/82773357

需求为:点击发送之后,发送内容,并将发送的内容清空

不做任何处理的话,小程序是不会帮你清空表单的;本次代码如下:

wxml

<form bindreset="foo">
    <input bindinput='getMsg' name="msg">请输入...</input>
    <button form-type="reset">发送</button>
</form>

js

  foo: function () {
    if (this.data.content) {
      //Do Something
      this.saveGMAMessage()
    } else {
      //Catch Error
     
    }
    this.setData({
      content: ''//将data的inputValue清空
    });
    return;
  },
  getMsg(e){
    this.setData({
      content:e.detail.value
    })
  },

原理就是点击提交,触发表单reset事件,判断是否有内容输入,有则执行发送请求;然后将已经绑定content的input值清空;

猜你喜欢

转载自blog.csdn.net/qq_23521659/article/details/82773357
今日推荐