HTMLTextAreaElement: selectionStart 属性
HTMLTextAreaElement 接口的 selectionStart 属性指定了 <textarea> 元素中当前文本选择的开始位置。它是一个表示选中文字开始索引的数字。它可用于检索和设置 <textarea> 中选中文字开始索引的起始位置。
当没有选中任何内容时,selectionStart 和 selectionEnd 的值都是 <textarea> 元素内光标(插入符号)的位置。
将 selectionStart 设置为大于当前 selectionEnd 值的值,会将 selectionStart 和 selectionEnd 属性都更新为该值。如果该值等于或大于 textLength,则两个属性都将设置为 textLength 属性值。
可以检索和设置该属性值,而无需 <textarea> 获得焦点,但需要元素获得焦点才能使 ::selection 伪元素匹配选中的文本。
将 selectionStart 设置为新值会触发 selectionchange 和 select 事件。