[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/API/HTMLInputElement/setSelectionRange [Back]  [Original]

HTMLInputElementsetSelectionRange() - Web API | MDN

MDN Web Docs

View in English Always switch to English

HTMLInputElementsetSelectionRange()

20157

HTMLInputElement.setSelectionRange <input> <textarea>

HTMLInputElement.selectionStartHTMLInputElement.selectionEnd HTMLInputElement.selectionDirection

passwordsearchteltext url InvalidStateError

HTMLInputElement.select()

js
setSelectionRange(selectionStart, selectionEnd)
setSelectionRange(selectionStart, selectionEnd, selectionDirection)

selectionEnd selectionStart selectionEnd

selectionStart

0 value value

selectionEnd

0 value value

selectionDirection

  • "forward"
  • "backward"
  • "none"

(undefined)

InvalidStateError DOMException

passwordsearchteltext url

Mozillazil

HTML

html
<input type="text" id="text-box" size="20" value="Mozilla" />
<button ></button>

JavaScript

js
function selectText() {
  const input = document.getElementById("text-box");
  input.focus();
  input.setSelectionRange(2, 5);
}

HTML
# dom-textarea/input-setselectionrange-dev


Web Proxy Viewer  |  New URL  |  Original Page