chrome是否支持document.selection ?

Does chrome supports document.selection?

本文关键字:selection document 支持 是否 chrome      更新时间:2023-09-26

我是javascript新手,试图执行:

document.selection.createRange();

但是document.selection总是返回undefined

我用的是最新版的chrome。

我做错了什么?

谢谢!

使用window.getSelection(),这是最跨浏览器兼容的(在所有主要浏览器的当前版本中都支持),并且是标准。Chrome当然像其他浏览器一样完全支持它。

document.selection只能用于IE <9 .

试试document.getSelection()window.getSelection()

下面是我在chrome中测试的一个快速示例

http://jsfiddle.net/hgDwx/

浏览器对基于IE11和Chrome 87.04280.141的selection对象的支持

<表类> 成员IE 铬 tbody> <<tr> document.selection 对没有道明> tr> window.selection 没有道明> 有道明> tr> document.getSelection() 没有道明> window.getSelection() 没有道明> tbody>

window.getSelection()代替。

https://developer.mozilla.org/en/DOM/window.getSelection