テキストをクリックしてクリップボードにコピー

4519 ワード


<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title> title>
  <style>
    #copyContent {
      background: transparent;
      border: 0;
      cursor: pointer;
      resize: none;
      height: 70px;
      width: 150px;
    }

    #copyContent:focus {
      box-shadow: 0 0 0 0;
      outline: 0;
      outline-offset: 0;
    }
  style>
head>

<body>

  <textarea id="copyContent" onclick=copyContent()> textarea>

  <script>
    function copyContent() {
      let e = document.getElementById("copyContent");// contents
      e.select(); // 
      let succ = document.execCommand("Copy"); // 
      if (succ) {
        alert(" ")
      }
    }
  script>
body>

html>