tencent cloud

键盘
最后更新时间:2024-07-16 17:52:30
键盘
最后更新时间: 2024-07-16 17:52:30

onKeyboardHeightChange

该 API 使用方法为 wx.onKeyboardHeightChange(function listener)
功能说明:监听键盘高度变化事件。
参数及说明:function callback,键盘高度变化事件的监听函数。
监听函数参数:Object res。
属性
类型
说明
height
number
键盘高度
示例代码:
wx.onKeyboardHeightChange(res => {
console.log(res.height)
})

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) // 需传入与监听时同一个的函数对象

getSelectedTextRange

该 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)
}
})

本页内容是否解决了您的问题?
您也可以 联系销售 提交工单 以寻求帮助。

文档反馈