removeAllRanges()方法不适用于chrome

时间:2017-03-30 18:57:55

标签: javascript html5

您好的想法是复制选定的节点然后文本然后删除选择,但我不知道为什么它不起作用:

var sel = window.getSelection();
        var range = sel.getRangeAt(0);
        var ancestor = sel.getRangeAt(0).commonAncestorContainer;
        var child = ancestor.childNodes;
        var len = child.length, div=[], text = [];

        for (var i =0; i<len; i++){
            div.push(child[i].localName);
            text.push(child[i].textContent);
        }
        sel.removeAllRanges();

0 个答案:

没有答案