点击文字复制到剪切板


<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>

你可能感兴趣的:(html+css)