https://www.bbsmax.com/A/GBJrejw3z0/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>copy</title>
</head>
<body>
<span id='copy'>複製哈哈哈哈啊哈哈</span>
<button id='btn'>複製</button>
</body>
<script type="text/javascript">
function copyText()
{
var Url2=document.getElementById("copy").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('複製成功');
}
document.getElementById('btn').onclick = function() {
copyText()
}
</script>
</html>