HTMLTextAreaElement: selectionStart 屬性
HTMLTextAreaElement 介面的 selectionStart 屬性指定了 <textarea> 元素中當前文字選擇的開始位置。它是一個表示選中文字開始索引的數字。它可用於檢索和設定 <textarea> 中選中文字開始索引的起始位置。
當沒有選中任何內容時,selectionStart 和 selectionEnd 的值都是 <textarea> 元素內游標(插入符號)的位置。
將 selectionStart 設定為大於當前 selectionEnd 值的值,會將 selectionStart 和 selectionEnd 屬性都更新為該值。如果該值等於或大於 textLength,則兩個屬性都將設定為 textLength 屬性值。
可以檢索和設定該屬性值,而無需 <textarea> 獲得焦點,但需要元素獲得焦點才能使 ::selection 偽元素匹配選中的文字。
將 selectionStart 設定為新值會觸發 selectionchange 和 select 事件。