getSelectedText

来源:互联网 发布:mac os x恢复出厂设置 编辑:程序博客网 时间:2024/05/22 13:27

跨浏览器的方法,用于得到光标选中的文字,来自<<javascript: The Definitive Guide>>


 

There is one minor incompatibility in the Example. The getSelection() methods of the Window and Document object do not return selected text if it is within an <input> or <textarea> form element: they only return text selected from the body of the document itself. The IE document.selection property, on the other hand, returns selected text from anywhere in the document.

In Firefox, text input elements define selectionStart and selectionEnd properties that you can use to query (or set) the selected text. For example:

 


原创粉丝点击