请问如何清空input组件中已经输入的内容?
发布于 5 年前 作者 lhe 14088 次浏览 来自 问答

如题

4 回复

为空没用  要设为空数组

<view class="main">
  <view class="section">
    <textarea id="idrecord" class="record" maxlength="0" bindchange="bindChange" value="{{record}}" placeholder="聊天记录" auto-height />
  </view>
  <view class="section">
    <form>
      <input id="idsendmsg" class="sendtxt" bindchange="bindChange" value="{{sendmsg}}" placeholder="消息" type="text" auto-focus />
      <view class="btn-area">
        <button form-type="reset" type="primary" bindtap="btnSendMsg">发送消息</button>
      </view>
    </form>
  </view>

需要清空的加在form里,button设置为form-type=“reset”

绑定输入事件 返回空

<input placeholder=“姓名” auto-focus  value="{{name}}"/>

data: {

    name: ‘’

  },

  onClearTap: function (e) {

    this.setData({

      name: ‘’

    })

  },

回到顶部