[HTML] 纯文本查看 复制代码 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="text">被复制的内容</div>
<button id="copy">复制</button>
<script>
document.getElementById('copy').addEventListener('click', function() {
var text = document.getElementById('text').innerText;
var input = document.createElement('input');
input.setAttribute('value', text);
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
alert('复制成功');
})
</script>
</body>
</html> |