<body style="background-color:orange;">
<div onclick="copyToClipboard()">
<input type="text" disabled id="textToCopy" value="123456">
</div>
<script>
async function copyToClipboard() {
const copyText = document.getElementById('textToCopy')
try {
await navigator.clipboard.writeText(copyText.value)
alert.log('複製成功')
alert('複製成功')
} catch (err) {
alert.error('複製失敗:', err)
}
}
</script>
</body>
別忘了引js