<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Copy</title>
</head>
<body>
  <button onclick="copyText(new Date().toLocaleString())">Copy</button>
  <script>
    function copyText(text) {
      if (!navigator.clipboard) {
        return;
      }
      navigator.clipboard.writeText(text).then(()=>{
        console.log('Async: Copying to clipboard was successful!');
      }, (error)=>{
        console.error('Async: Could not copy text: ', error);
      })
    }
  </script>
</body>
</html>

添加新评论