I am not able to get the selection object's start and end offsets in Opera (v9.50) when the selection is collapsed (ie just point and click instead of highlighting text). 这是我的简单测试代码,在 FF 和 Safari 中有效,但在 Opera 中无效。
<html>
<head>
<script type="text/javascript">
function showSelection()
{
userSelection = window.getSelection();
alert('Start: '+userSelection.anchorOffset+'\nEnd: '+userSelection.focusOffset);
}
</script>
</head>
<body>
<div onmouseup="showSelection();">
<p>Lorem ipsum dolor <strong>sit amet</strong></p>
</div>
</body>
</html>
当我选择一个文本时,它可以工作,但只是指向和单击总是将偏移量返回为 0。我错过了什么?提前致谢。