Textarea Selection Index

依然范特西╮ 提交于 2019-12-13 03:14:13

问题


I have a textarea control in my website. I want to retrieve start and end position of selected text in the text area, for Internet Explorer.

How can I do it?


回答1:


Might I encourage you to use Rangy?

A cross-browser JavaScript range and selection library. It provides a simple standards-based API for performing common DOM Range and Selection tasks in all major browsers, abstracting away the wildly different implementations of this functionality between Internet Explorer and DOM-compliant browsers.

See Selection Objects in Rangy.




回答2:


txtarea.selectionStart

and

txtarea.selectionEnd

are the indices of the selection.

This StackOverflow question shows you how to use them.

To read more on selected text, see this Introduction to Range. Specifically, you will have to use Microsoft Text Range for Internet Explorer.



来源:https://stackoverflow.com/questions/6974807/textarea-selection-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!