<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p id="aa">哈哈哈1</p>
<button type="button" id="button">复制</button>
<script type="text/javascript">
let aa = document.getElementById("aa")
let btn = document.getElementById("button")
btn.onclick = function() {
copyToClipboard(aa.innerHTML)
alert("复制成功")
}
const copyToClipboard = (text) =>
navigator.clipboard?.writeText && navigator.clipboard.writeText(text)
</script>
</body>
</html>
点击按钮复制功能