Skip to content

Keyboard

onKeyboardHeightChange

TIP

The API usage is as follows: wx.onKeyboardHeightChange(function listener)

  • Functional description: Listen for keyboard height change events

  • Parameters and descriptions: function callback,Listener function for keyboard height change events

  • object.success callback function parameters: Object res。

    PropertiesTypeDescription
    heightnumberKeyboard height
  • Sample code:

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

hideKeyboard

TIP

The API usage is as follows: wx.hideKeyboard(Object object)

  • Functional description: After the input, textarea, etc. are focused and the keyboard is pulled up, manually call this interface to close the keyboard

  • Parameters and descriptions: Object object。

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Sample code:

js
wx.hideKeyboard({
  complete: res => {
    console.log('hideKeyboard res', res)
  }
})

offKeyboardHeightChange

TIP

The API usage is as follows: wx.offKeyboardHeightChange(function listener)

  • Functional description: Remove listener function for keyboard height change events

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

  • Sample code:

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

wx.onKeyboardHeightChange(listener)
wx.offKeyboardHeightChange(listener) // Pass the same function object used for listening.

getSelectedTextRange

TIP

The API usage is as follows: wx.getSelectedTextRange(Object object)

  • Functional description: After the input, textarea, etc. are focused, get the cursor position of the input box Note: This interface is only valid when called when focused

  • Parameters and descriptions: Object object。

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • object.success callback function parameters: Object res。

    PropertiesTypeDescription
    startnumberThe starting position of the input box cursor
    endnumberThe ending position of the input box cursor
  • Sample code:

js
wx.getSelectedTextRange({
  complete: res => {
    console.log('getSelectedTextRange res', res.start, res.end)
  }
})