小程序 input输入 删除 聚焦等方法

Page({
    data: {
     clearsearch: false
    },
  inputfocus: function (e) {
    this.setData({
      clearsearch: true,
    })
  },
  inputblur: function (e) {
    this.setData({
      clearsearch: false,//删除按钮显示隐藏
      inputvalue:' '//input输入的值
    })
  },
  inputvalue: function (e) {
    this.setData({
      clearsearch: true,
      inputvalue: e.detail.value
    })
  },
  // 清空筛选
  clearsearch: function (e) {
    var inputvalue = this.data.inputvalue
    this.setData({
      inputvalue: '',
      clearsearch: false
    })
  }
})    
<input placeholder="请输入手机号" placeholder-class="phcolor" value="{{inputvalue}}" bindblur="inputblur" bindfocus="inputfocus" bindinput="inputvalue" class="tellnum"/>
<view class='clearsearch' bindtap='clearsearch' hidden='{{!clearsearch}}'><icon type="clear" size="17"/></view>

 

 

posted @ 2020-07-06 17:46  瑶玲  阅读(1723)  评论(0编辑  收藏  举报