【问题标题】:Collapsed selection in OperaOpera中的折叠选择
【发布时间】:2010-09-27 11:21:05
【问题描述】:

I am not able to get the selection object's start and end offsets in Opera (v9.50) when the selection is collapsed (i.e. 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。我错过了什么?提前致谢。

【问题讨论】:

    标签: javascript selection opera offset


    【解决方案1】:

    当您单击时,Opera 似乎没有做出选择。我不知道你想要实现什么,但如果你想获得选定的文本,Opera 还实现了“document.selection”(可能支持其他 IE 脚本),这样你就可以执行“document .selection.createRange().text"(不是很有帮助,因为当没有选择任何内容时,它将返回一个空字符串)。

    我认为你对这个不走运。

    【讨论】:

      【解决方案2】:

      我建议把这个放在 Opera 论坛上,肯定会有人(例如开发人员)可以给你一个明确的是或否。

      Opera forum

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-11
        • 2012-04-24
        • 2018-08-02
        • 1970-01-01
        • 2013-08-21
        相关资源
        最近更新 更多