HTMLInputElement: selectionEnd property
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015ë 7ìâ©.
HTMLInputElement ì¸í°íì´ì¤ì selectionEnd ìì±ì ì íë í
ì¤í¸ì ë ì¸ë±ì¤ë¥¼ ê°ë¦¬í¤ë ì«ìì
ëë¤. ì´ë ì íë í
ì¤í¸ê° ìë¤ë©´ íì¬ í
ì¤í¸ ì¸íì´ ì»¤ì ìì¹ ë°ë¡ ë¤ìì 문ì ì¤íì
ì ë°íí©ëë¤.
ì°¸ê³ :
ð WHATWG forms specì ë°ë¥´ë©´, selectionEnd ìì±ì text, search, URL, tel, password íì
ì ê°ì§ ì¸íìë§ ì ì©ë©ëë¤. ìµì ë¸ë¼ì°ì ììë, ì´ì ê°ì ì¸í íì
ì´ ìë ê²½ì°ì selectionEnd ìì±ì ì¤ì í ê²½ì° ìì¸ê° ë°ìë©ëë¤. ëí, í
ì¤í¸ ì¸íì´ ìë ììì selectionEnd ìì±ì¼ë¡ ì ê·¼í ê²½ì° ì´ ìì±ì null 를 ë°íí©ëë¤.
selectionEnd ê° selectionStart ë³´ë¤ ìì¼ë©´,
ë ê°ì 모ë selectionEnd ì ê°ì¼ë¡ ì²ë¦¬ë©ëë¤.
ê°
ììì ëë¤.
ìì
>HTML
<!-- í
ì¤í¸ ì¸íì´ ìë ììì selectionEnd ì¬ì©í기 -->
<label for="color">type=colorì selectionStart ìì±</label>
<input id="color" type="color" />
<!-- í
ì¤í¸ ì¸í ììì selectionEnd ì¬ì©í기 -->
<fieldset>
<legend>type=textì selectionEnd ìì±</legend>
<label for="pin">Input PIN</label>
<input type="text" id="pin" value="impossible PIN: 102-12-145" />
<button id="pin-btn" type="button">PIN correction</button>
</fieldset>
JavaScript
const colorEnd = document.getElementById("color");
const text = document.querySelector("#pin");
const pinBtn = document.querySelector("#pin-btn");
const validPinChecker = /[^\d{3}-\d{2}-\d{3}]/g;
const selectionEnd = text.value.length;
const selectedText = text.value.substring(text.selectionStart, selectionEnd);
pinBtn.addEventListener("click", () => {
const correctedText = selectedText.replace(validPinChecker, "");
text.value = correctedText;
});
// 결과를 íì¸í기 ìí´ ë¸ë¼ì°ì ì ì½ìì íì¸í´ ë³´ì¸ì
console.log(colorEnd.selectionEnd); // ê²°ê³¼ : null
ê²°ê³¼
ëª ì¸ì
| Specification |
|---|
| HTML > # dom-textarea/input-selectionend > |
ë¸ë¼ì°ì í¸íì±
ê°ì´ 보기
HTMLTextAreaElement.selectionEndpropertyHTMLInputElement.selectionStartpropertyHTMLInputElement.setSelectionRangemethod