key.md 2.4 KB
Newer Older
L
liumingchu 已提交
1 2 3
#### uni.hideKeyboard()

隐藏软键盘
4 5

隐藏已经显示的软键盘,如果软键盘没有显示则不做任何操作。
M
mehaotian 已提交
6 7 8

**平台差异说明**

9 10 11
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序|快手小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|√|√|√|√|x|√|√|√|
M
mehaotian 已提交
12

L
liumingchu 已提交
13 14

#### uni.onKeyboardHeightChange(CALLBACK)
15 16 17 18 19

监听键盘高度变化

**平台差异说明**

20 21 22
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序|快手小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|HBuilderX 2.2.3+|x|基础库2.7+|x|x|x|√|√|
L
liumingchu 已提交
23

24 25 26 27
**CALLBACK 返回参数**

|参数|类型|说明|
|:-|:-|:-|
L
liumingchu 已提交
28 29 30 31 32 33 34 35 36
|height|Number|键盘高度|

**示例代码**

```js
uni.onKeyboardHeightChange(res => {
  console.log(res.height)
})
```
37

38 39 40 41 42 43
#### uni.offKeyboardHeightChange(CALLBACK)

取消监听键盘高度变化事件

**平台差异说明**

44 45 46
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序|快手小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|HBuilderX 3.1.0+|x|基础库2.9.2+|x|x|x|x|x|
47 48 49 50 51 52 53

**示例代码**

```js
uni.offKeyboardHeightChange(callback)
```

54 55
#### uni.getSelectedTextRange(OBJECT)

折腾笔记 已提交
56
在input、textarea等focus之后,获取输入框的光标位置。注意:只有在focus的时候调用此接口才有效。目前仅支持 vue 页面,nvue 可以直接使用 weex 的 [getSelectionRange](https://weex.apache.org/zh/docs/components/input.html#getSelectionRange)
57 58 59

**平台差异说明**

60 61 62
|App|H5|微信小程序|支付宝小程序|百度小程序|字节跳动小程序|QQ小程序|快手小程序|
|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|HBuilderX 2.8.12+|HBuilderX 2.8.12+|基础库 2.7.0+|x|x|x|x|√|
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

**OBJECT 参数说明:**

| 参数名 | 类型 | 默认值 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| success | Function |  | 否 | 接口调用成功的回调函数 |
| fail | Function |  | 否 | 接口调用失败的回调函数 |
| complete | Function |  | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |

**success 返回参数说明:**

| 属性 | 类型 | 说明 |
| --- | --- | --- |
| start | Number | 输入框光标起始位置 |
| end | Number | 输入框光标结束位置 |

**示例代码**

```js
uni.getSelectedTextRange({
  success: res => {
    console.log('getSelectedTextRange res', res.start, res.end)
  }
})
```