getHTMLOfSelection: function() {
var range;
if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
// this.document.execCommand("Copy", true);
return range.htmlText;
} else if (window.getSelection) {
var selection = window.getSelection();
if (selection.rangeCount > 0) {
range = selection.getRangeAt(0);
var clonedSelection = range.cloneContents();
var div = document.createElement('div');
div.appendChild(clonedSelection);
var elms = div.querySelectorAll("*[style]");
Array.prototype.forEach.call(elms, function(elm) {
var clr = elm.style.display || "";
if (clr === 'none') {
elm.innerText = '';
}
});
return div.innerHTML;
} else {
return '';
}
} else {
return '';
}
}
这是我的代码,但是在针对class,id
编写CSS时(例如display:none
,visiblity:hidden
和height:0
),它不起作用。