# uni.hideKeyboard()

hide soft keyboard

Hide the displayed soft keyboard, and do nothing if the soft keyboard is not displayed.

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 京东小程序
x

# uni.onKeyboardHeightChange(CALLBACK)

Monitor keyboard height changes

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 京东小程序
HBuilderX 2.2.3+ x Basic library 2.7+ HBuilderX 3.6.8+ x x

parameter

function listener

Listener function for keyboard height change event

parameter

Object res

Parameter Type Description
height Number Keyboard height

Example Code

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

# uni.offKeyboardHeightChange(CALLBACK)

Cancel listening to the keyboard height change event

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 京东小程序
HBuilderX 3.1.0+ x Basic library 2.9.2+ HBuilderX 3.6.8+ x x x x

parameter

function listener

The listening function passed in by onKeyboardHeightChange. If this parameter is not passed, all listener functions will be removed.

Example Code

const listener = function (res) { console.log(res) }

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

# uni.getSelectedTextRange(OBJECT)

After input, textarea, etc. focus, get the cursor position of the input box. Note: This interface is valid only when calling the focus. Currently only supports vue pages, nvue can directly use weex's getSelectionRange.

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 京东小程序
HBuilderX 2.8.12+ HBuilderX 2.8.12+ Basic Library 2.7.0+ x x x x x

OBJECT parameter description:

parameter name type default value required description
success Function No Callback function for successful interface call
fail Function No The callback function of interface call failure
complete Function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

success return parameter description:

Property Type Description
start Number The starting position of the cursor in the input box
end Number End position of input box cursor

Example Code

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