HTMLTextAreaElement: selectionEnd 属性
HTMLTextAreaElement
接口的 selectionEnd
属性指定了 <textarea>
元素中当前文本选区的结束位置。它是一个数字,表示选中文本的最后一个索引。它可用于获取和设置 <textarea>
选中文本的结束索引。
当没有选中任何文本时,
和 selectionStart
selectionEnd
的值都是 <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>
HTMLTextAreaElement
HTMLTextAreaElement.selectionStart
HTMLTextAreaElement.selectionDirection
HTMLTextAreaElement.textLength
selectionChange
事件HTMLTextAreaElement.select()
HTMLTextAreaElement.setSelectionRange()
HTMLTextAreaElement.setRangeText()
HTMLInputElement.selectionEnd
Selection
::selection
伪元素