<p id="p1">
...here is a lot of text (html) mixed with php...
</p>
<button onclick="copyToClipboard('#p1')">Copy to clipboard</button>
------
JS
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,结果将被复制但没有粗体,下划线,行和其他格式化的东西.我如何复制它,因为它默认显示?