onKeyboardHeightChange
该 API 使用方法为 wx.getSelectedTextRange(Object object)
功能说明:在 input、textarea 等 focus 之后,获取输入框的光标位置。只有在 focus 的时候调用此接口才有效。
参数及说明:Object object。
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数:Object res。
属性 | 类型 | 说明 |
start | number | 输入框光标起始位置 |
end | number | 输入框光标结束位置 |
示例代码:
wx.getSelectedTextRange({complete: res => {console.log('getSelectedTextRange res', res.start, res.end)}})
hideKeyboard
该 API 使用方法为 wx.hideKeyboard(Object object)
功能说明:在 input、textarea 等 focus 拉起键盘之后,手动调用此接口收起键盘,使用方法为。
参数及说明:Object object。
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
示例代码:
wx.hideKeyboard({complete: res => {console.log('hideKeyboard res', res)}})
offKeyboardHeightChange
该 API 使用方法为 为 wx.offKeyboardHeightChange(function listener)
功能说明:移除键盘高度变化事件的监听函数。
参数及说明:function listener,onKeyboardHeightChange 传入的监听函数。不传此参数则移除所有监听函数。。
示例代码:
const listener = function (res) { console.log(res) }wx.onKeyboardHeightChange(listener)wx.offKeyboardHeightChange(listener) // 需传入与监听时同一个的函数对象
getSelectTextRange
该 API 使用方法为 wx.getSelectedTextRange(Object object)
功能说明:在 input、textarea 等 focus 之后,获取输入框的光标位置。只有在 focus 的时候调用此接口才有效。
参数及说明:Object object。
属性 | 类型 | 默认值 | 必填 | 说明 |
success | function | - | 否 | 接口调用成功的回调函数 |
fail | function | - | 否 | 接口调用失败的回调函数 |
complete | function | - | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数:Object res。
属性 | 类型 | 说明 |
start | number | 输入框光标起始位置 |
end | number | 输入框光标结束位置 |
示例代码:
wx.getSelectedTextRange({complete: res => {console.log('getSelectedTextRange res', res.start, res.end)}})