title: Taro.getSelectedTextRange(option)

sidebar_label: getSelectedTextRange

Obtains the cursor position of the input box after the focus of input, textarea, etc. Note: This API works only when it is called during the focus process.

Reference

Type

  1. (option?: Option) => Promise<SuccessCallbackResult>

Parameters

Option

Property Type Required Description
complete (res: CallbackResult) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: CallbackResult) => void No The callback function for a failed API call
success (res: CallbackResult) => void No The callback function for a successful API call

SuccessCallbackResult

Property Type Description
end number End position of the cursor in the input box
start number Start position of the cursor in the input box
errMsg string call result

Sample Code

  1. Taro.getSelectedTextRange({
  2. complete: res => {
  3. console.log('getSelectedTextRange res', res.start, res.end)
  4. }
  5. })

API Support

API WeChat Mini-Program H5 React Native
Taro.getSelectedTextRange ✔️