跨浏览器的方法,用于得到光标选中的文字,来自<<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:
跨浏览器选文
本文介绍了一种跨浏览器兼容的方法来获取用户在网页上选中的文本内容。该方法通过判断当前浏览器环境并使用相应的API实现,支持现代浏览器的Window.getSelection()方法、较旧浏览器的Document.getSelection()方法以及Internet Explorer的document.selection.createRange().text。此外还提供了针对Firefox浏览器中输入框内文本选择的特定解决方案。
1646

被折叠的 条评论
为什么被折叠?



