HTMLTextAreaElement: selectionEnd 屬性
HTMLTextAreaElement 介面的 selectionEnd 屬性指定了 <textarea> 元素中當前文字選區的結束位置。它是一個數字,表示選中文字的最後一個索引。它可用於獲取和設定 <textarea> 選中文字的結束索引。
當沒有選中任何文字時, 和 selectionStartselectionEnd 的值都是 <textarea> 元素中游標(插入符)的位置。
將 selectionEnd 設定為小於當前 selectionStart 值的值會同時將 selectionEnd 和 selectionStart 屬性更新為該值。如果兩個值都小於 0,則兩個屬性都將設定為 textLength 屬性值。
可以在 <textarea> 元素未獲得焦點的情況下檢索和設定該屬性值,但元素需要獲得焦點才能使 偽元素匹配選中的文字。::selection
將 selectionEnd 設定為新值會觸發 和 selectionchange 事件。select
值
一個非負整數。
示例
js
const textarea = document.getElementById("text-box");
const end = textarea.selectionEnd;
規範
| 規範 |
|---|
| HTML # dom-textarea/input-selectionend |
瀏覽器相容性
載入中…
另見
<textarea>HTMLTextAreaElementHTMLTextAreaElement.selectionStartHTMLTextAreaElement.selectionDirectionHTMLTextAreaElement.textLengthselectionChange事件HTMLTextAreaElement.select()HTMLTextAreaElement.setSelectionRange()HTMLTextAreaElement.setRangeText()HTMLInputElement.selectionEndSelection::selection偽元素