<!DOCTYPE html>
<html>
<body onclick="myFunction(event)">
<p>The executeCommand() method executes a specified command on selected text or section.</p>
<script>
document.designMode = "on";
let p=document.querySelector('p')
let y=document.querySelector('body')
function myFunction(event) {
let a=p.innerText
let b=document.createElement('input')
b.value=a
y.appendChild(b)
b.select()
document.execCommand("copy")
y.removeChild(b)
}
</script>
</body>
</html>
JavaScript实现文本复制
最新推荐文章于 2024-07-03 10:51:25 发布