HTMLInputElement: selectionStart ããããã£
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æ.
selectionStart 㯠HTMLInputElement ã¤ã³ã¿ã¼ãã§ã¤ã¹ã®ããããã£ã§ã鏿ããã¹ãã®å
é ã¤ã³ããã¯ã¹ãè¡¨ãæ°å¤ã§ããä½ã鏿ããã¦ããªãå ´åã¯ã <input> è¦ç´ å
ã®ããã¹ãå
¥åã«ã¼ã½ã«ï¼ãã£ã¬ããï¼ã®ä½ç½®ãè¿ãã¾ãã
ã¡ã¢:
WHATWG ã®ãã©ã¼ã 仿§æ¸ã«ããã¨ã selectionStart ããããã£ã¯ textãsearchãURLãtelãpassword ã®åå
¥ååã«ã®ã¿é©ç¨ããã¾ããç¾è¡ã®ãã©ã¦ã¶ã¼ã§ã¯ããã以å¤ã®å
¥ååã« selectionStart ããããã£ãè¨å®ããã¨ä¾å¤ãçºçãã¾ããããã«ãããã¹ã以å¤ã®å
¥åè¦ç´ ã§ selectionStart ããããã£ã«ã¢ã¯ã»ã¹ããã¨ããã®ããããã£ã¯ null ãè¿ãã¾ãã
selectionStart ã selectionEnd ããã大ãããªã£ãå ´åã両è
㯠selectionEnd ã¨æ±ããã¾ãã
å¤
éè² ã®æ°å¤ã§ãã
ä¾
>HTML
<!-- selectionStart ãéããã¹ãå
¥åè¦ç´ ã§ä½¿ç¨ -->
<label for="color">selectionStart ããããã£ã type=color ã«è¨å®</label>
<input id="color" type="color" />
<!-- selectionStart ãããã¹ãå
¥åè¦ç´ ã§ä½¿ç¨ -->
<fieldset>
<legend>selectionStart ããããã£ã type=text ã«è¨å®</legend>
<label for="statement">ããã¹ãå
ã® 'mdn' ã鏿ãã¦ãã ãã : </label>
<input
type="text"
id="statement"
value="The mdn is a documentation repository." />
<button id="statement-btn">Select mdn text</button>
</fieldset>
JavaScript
const inputElement = document.getElementById("statement");
const statementBtn = document.getElementById("statement-btn");
const colorStart = document.getElementById("color");
statementBtn.addEventListener("click", () => {
inputElement.selectionStart = 4;
inputElement.selectionEnd = 7;
inputElement.focus();
});
// ãã©ã¦ã¶ã¼ã³ã³ã½ã¼ã«ãéãã¦åºåã確èªãã¦ãã ãã
console.log(colorStart.selectionStart); // Output : null
çµæ
仿§æ¸
| Specification |
|---|
| HTML> # dom-textarea/input-selectionstart> |
ãã©ã¦ã¶ã¼ã®äºææ§
é¢é£æ å ±
HTMLTextAreaElement.selectionStartããããã£HTMLInputElement.selectionEndããããã£HTMLInputElement.setSelectionRangeã¡ã½ãã