我想单击按钮时将图像复制到剪贴板,但是当我粘贴它时,它始终有我想要删除的style="..."。如何在按钮单击时将干净的HTML复制到剪贴板?
function copy(selector) {
var $temp = $("
$("body").append($temp);
$temp.attr("contenteditable", true)
.html($(selector).html())
.select()
.on("focus", function() { document.execCommand('selectAll', false, null); })
.focus();
document.execCommand("copy");
$temp.remove();
}
下面是HTML:
Copy Keeping Format
当我点击该按钮,如TinyMCE的它显示的图像将其粘贴到网页的文本编辑器,但是当我打开源代码有style="..."我显然不需要:
我如何将其粘贴只是以下?
我如何检查数据将被复制?
console.log() // what var to print to check the data that will be copy by execcommand
UPDATE
我试着右击图像,并选择复制图像并将其粘贴到文本编辑器和查看源代码,并获得干净的IMG HTML没有style="..."所以它不是文本编辑器加上style="..."对不对?
+0
'$ temp.removeAttr( “风格”)' –
+0
@mplungjan我猜的风格属性由TinyMCE的编辑器添加,没有? –
+0
如果它不在临时对象上,那么是的 –