html内容
<div hidden id="keydiv">Hello World</div>
<btn class="btn btn-sm btn-default" onclick="copyText()">点此复制</btn>
js代码
function copyText() {
var Url2 = document.getElementById("keydiv").innerText;
var oInput = document.createElement(‘input‘);
oInput.value = Url2;
document.body.appendChild(oInput);
oInput.select();
document.execCommand("Copy");
oInput.className = ‘oInput‘;
oInput.style.display = ‘none‘;
alert(‘复制成功‘);
}
原文地址:https://www.cnblogs.com/ylblogss/p/9644532.html
时间: 2024-10-08 16:35:34