为什么在屏幕上呈现用户选择?

时间:2017-08-14 10:17:50

标签: javascript browser range selection w3c

我正在尝试以实际方式创建用户选择。 Here is the plunker。这是简单的设置:

<p>Tim O'Reilly calls for a Blogger Code of Conduct. His proposals are:</p>
<ol>
    <li>Take responsibility not just for your own words, but for the
        comments you allow on your blog.</li>
    <li>Label your tolerance level for abusive comments.</li>
    <li>Consider eliminating anonymous comments.</li>
</ol>

<script>
    var range = document.createRange();
    var startPar = document.querySelector('p').firstChild;
    var endLi = document.querySelector('li:nth-child(2)').firstChild;
    range.setStart(startPar,13);
    range.setEnd(endLi,17);
    console.log(range.toString());
</script>

一切似乎工作正常,我得到预期的输出到控制台,但是屏幕上没有选择文本。这是设计吗?

1 个答案:

答案 0 :(得分:1)

您已找到范围,但现在需要告诉浏览器选择它。例如:

u"\u2660"