<!DOCTYPE html>
<html>
<head>
    <title>复制操作</title>
    <script>
        function copyText() {
            var text = document.getElementById('textToCopy').innerText;

            navigator.clipboard.writeText(text)
                .then(function() {
                    console.log('文本已成功复制到剪贴板');
                })
                .catch(function(err) {
                    console.error('无法复制文本到剪贴板:', err);
                });
        }
    </script>
</head>
<body>
    <div id="textToCopy">要复制的文本</div>
    <button onclick="copyText()">复制文本</button>
</body>
</html>