tt.hideKeyboard
收藏
我的收藏

基础库 1.0.0 开始支持本方法,这是一个异步方法。

<input><textarea>等组件中 focus 拉起键盘后,手动调用此接口可以收起键盘。

前提条件
业务背景
使用限制
注意事项
支持沙盒
相关教程

语法

tt.hideKeyboard(options)

参数说明

options 为 object 类型,属性如下:

属性名类型默认值必填说明最低支持版本
successfunction
接口调用成功的回调函数
1.0.0
failfunction
接口调用失败的回调函数
1.0.0
completefunction
接口调用结束的回调函数(调用成功、失败都会执行)
1.0.0

回调成功

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"hideKeyboard:ok"
1.0.0

回调失败

object 类型,属性如下:

属性名类型说明最低支持版本
errMsgstring
"hideKeyboard:fail" + 详细错误信息
1.0.0

代码示例

<!-- index.ttml -->
<view>
  <textarea bindfocus="onTextFocus" placeholder="请输入" />
  <button type="primary" bindtap="hideKeyboard">收起键盘</button>
</view>
Page({
  onTextFocus: function (e) {
    console.log("开始输入", e);
  },
  hideKeyboard() {
    tt.hideKeyboard({
      success(res) {
        console.log("hideKeyboard 调用成功", res);
      },
      fail(res) {
        console.log("hideKeyboard 调用失败", res);
      },
    });
  },
});