<!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>
<button>复制</button>
<script>
const btn = document.querySelector('button')
btn.onclick = () => {
navigator.clipboard
.writeText('123456413212')
.then(() => {
console.log('复制成功');
})
.catch(() => {
console.log('复制失败');
});
}
</script>
</body>
</html>
javascript实现一键复制文本功能
最新推荐文章于 2024-05-09 15:15:12 发布