您好的想法是复制选定的节点然后文本然后删除选择,但我不知道为什么它不起作用:
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();