tencent cloud

键盘
最后更新时间:2025-07-04 16:52:52
键盘
最后更新时间: 2025-07-04 16:52:52

updateKeyboard

该 API 使用方法为 wx.updateKeyboard(Object object)
功能说明:更新键盘输入框内容。只有当键盘处于拉起状态时才会产生效果。
参数及说明:Object object
属性
类型
默认值
必填
说明
value
string
-
键盘输入框的当前值
success
function
-
接口调用成功的回调函数
fail
function
-
接口调用失败的回调函数
complete
function
-
接口调用结束的回调函数(调用成功、失败都会执行)

showKeyboard

该 API 使用方法为 wx.showKeyboard(Object object)
功能说明:显示键盘。
参数及说明:Object object
属性
类型
默认值
必填
说明
defaultValue
string
-
键盘输入框显示的默认值
maxLength
number
-
键盘中文本的最大长度
multiple
boolean
-
是否为多行输入
confirmHold
boolean
-
当点击完成时键盘是否保持显示
confirmType
string
-
键盘右下角 confirm 按钮的类型,只影响按钮的文本内容
type
string
text
键盘类型
success
function
-
接口调用成功的回调函数
fail
function
-
接口调用失败的回调函数
complete
function
-
接口调用结束的回调函数(调用成功、失败都会执行)
confirmType 的合法值:
合法值
说明
done
完成
next
下一个
search
搜索
go
前往
send
发送
type 的合法值:
合法值
说明
text
文本输入键盘
number
数字输入键盘
digit
带小数点的数字键盘

onKeyboardInput

该 API 使用方法为 wx.onKeyboardInput(function listener)
功能说明:监听键盘输入事件。
参数及说明:function listener,键盘输入事件的监听函数,参数如下:
属性
类型
说明
value
string
键盘输入的当前值

onKeyboardHeightChange

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

onKeyboardConfirm

该 API 使用方法为 wx.onKeyboardConfirm(function listener)
功能说明:监听用户点击键盘 Confirm 按钮时的事件。
参数及说明:function listener,用户点击键盘 Confirm 按钮时的事件的监听函数,参数如下:
属性
类型
说明
value
string
键盘输入的当前值

onKeyboardComplete

该 API 使用方法为 wx.onKeyboardComplete(function listener)
功能说明:监听键盘收起的事件。
参数及说明:function listener,键盘收起的事件的监听函数,参数如下:
属性
类型
说明
value
string
键盘输入的当前值

offKeyboardInput

该 API 使用方法为 wx.offKeyboardInput(function listener)
功能说明:移除键盘输入事件的监听函数。
参数及说明:function listener,onKeyboardInput 传入的监听函数。不传此参数则移除所有监听函数。
示例代码:
const listener = function (res) { console.log(res) }

wx.onKeyboardInput(listener)
wx.offKeyboardInput(listener) // 需传入与监听时同一个的函数对象

offKeyboardHeightChange

该 API 使用方法为 wx.offKeyboardHeightChange(function listener)
功能说明:移除键盘高度变化事件的监听函数。
参数及说明:function listener,onKeyboardHeightChange 传入的监听函数。不传此参数则移除所有监听函数。
示例代码:
const listener = function (res) { console.log(res) }

wx.onKeyboardHeightChange(listener)
wx.offKeyboardHeightChange(listener) // 需传入与监听时同一个的函数对象

offKeyboardConfirm

该 API 使用方法为 wx.offKeyboardConfirm(function listener)
功能说明:移除用户点击键盘 Confirm 按钮时的事件的监听函数。
参数及说明:function listener,onKeyboardConfirm 传入的监听函数。不传此参数则移除所有监听函数。
示例代码:
const listener = function (res) { console.log(res) }

wx.onKeyboardConfirm(listener)
wx.offKeyboardConfirm(listener) // 需传入与监听时同一个的函数对象

offKeyboardComplete

该 API 使用方法为 wx.offKeyboardComplete(function listener)
功能说明:移除键盘收起的事件的监听函数。
参数及说明:function listener,onKeyboardComplete 传入的监听函数。不传此参数则移除所有监听函数。
示例代码:
const listener = function (res) { console.log(res) }

wx.onKeyboardComplete(listener)
wx.offKeyboardComplete(listener) // 需传入与监听时同一个的函数对象

hideKeyboard

该 API 使用方法为 wx.hideKeyboard(Object object)
功能说明:隐藏键盘。
参数及说明:Object object。
属性
类型
默认值
必填
说明
success
function
-
接口调用成功的回调函数
fail
function
-
接口调用失败的回调函数
complete
function
-
接口调用结束的回调函数(调用成功、失败都会执行)
示例代码:
wx.hideKeyboard({
complete: res => {
console.log('hideKeyboard res', res)
}
})

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

文档反馈