更新时间:2023-12-03 08:23:34
window.getSelection()
是您需要的除IE之外的所有主要浏览器< 9,它有不同的API。 window.getSelection()
返回 选择
( spec )您可以从中提取 DOM Range (规范)代表选择。
window.getSelection()
is what you need in all major browsers except IE < 9, which has a different API. window.getSelection()
returns a Selection
(spec) object from which you can extract a DOM Range (spec) representing the selection.
对于IE< 9,你可以看一下 document.selection
,或使用我自己的库 Rangy ,在所有主流浏览器中提供相同的基于标准的API。
For IE < 9, you can look at document.selection
, or use a library such as my own Rangy, which provides the same standards-based API in all major browsers.