我给用户提供了通过单击一个按钮复制div的html代码的能力,一些属性,比如视频:
<video loop muted autoplay>
变得像这样
<video loop="" muted="" autoplay="">
我不知道为什么会这样,这是我复制内容的代码:
/*copy to clipboard */
function copyToClipboard() {
// Create an auxiliary hidden input
var aux = document.createElement("input");
// Get the text from the element passed into the input
aux.setAttribute("value", document.getElementById('sampleeditor').innerHTML);
// Append the aux input to the body
document.body.appendChild(aux);
// Highlight the content
aux.select();
// Execute the copy command
document.execCommand("copy");
var tooltip = document.getElementById("myTooltip");
tooltip.innerHTML = "Copied";
// Remove the input from the body
document.body.removeChild(aux);
setTimeout(() => { tooltip.innerHTML = "Copy to clipboard"; }, 2000);
}
转载请注明出处:http://www.jubohx.com/article/20230511/2340322.html