为什么 window.getSelection () 在 Firefox 和 chrome 之间是不同的?



with:

<div contenteditable="true"> ... text.... <img src="image.png" height="50" width="50" onmouseup="alert(window.getSelection().isCollapsed)"> ... text... </div>

如果我在火狐警报中单击(在 img 上鼠标向上)说:"假", 在Chrome警报中说:"真实"。 为什么不同?(火狐似乎表明有选定的文本)

跟:

<div contenteditable="true"> ... text.... <img src="image.png" alt="hello" height="50" width="50" onmouseup="alert(window.getSelection().toString())"> ... text... </div>

如果我在火狐警报中单击(在 img 上鼠标向上)说:"你好", 在铬警报说:"。 为什么 Firefox 说我选择了"你好"文本?火狐错了,铬没有?

这是火狐中的一个已知错误: https://bugzilla.mozilla.org/show_bug.cgi?id=1417535

document/window.getSelection方法在Google Chrome,Safari和Internet Explorer中的工作方式与在Firefox和Opera中的工作方式不同。它在 Firefox 和 Opera 中返回一个字符串,并在 Google Chrome、Safari 和 Internet Explorer 中返回一个 selectionRange 对象(document.getSelect 方法与 Google Chrome、Safari 和 Internet Explorer 中的 window.getSelect 方法相同)。因此,不应使用此方法。

最新更新