Skip to main content
Version: 3.x

Taro.getSelectedTextRange(option)

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

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

Parameters

Option

PropertyTypeRequiredDescription
complete(res: CallbackResult) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: CallbackResult) => voidNoThe callback function for a failed API call
success(res: CallbackResult) => voidNoThe callback function for a successful API call

SuccessCallbackResult

PropertyTypeDescription
endnumberEnd position of the cursor in the input box
startnumberStart position of the cursor in the input box
errMsgstringcall result

Sample Code

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

API Support

APIWeChat Mini-ProgramH5React Native
Taro.getSelectedTextRange✔️