>  Q&A  >  본문

javascript - js实现ctrl + c 的复制功能?

js怎样实现ctrl + c 的复制功能?

迷茫迷茫2749일 전1095

모든 응답(4)나는 대답할 것이다

  • 怪我咯

    怪我咯2017-04-11 11:07:56

    <html>
      <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
          .text-input{
            border: none;
            outline:medium;
            box-shadow: none;
        }
            .copy-id:focus{
                border: none;
            }
        </style>
      </head>
      <body>
        <input readonly="readonly"  class="copy-id text-input" type="text" value="12333333333"/>
        <button class="copy">复制</button>
      </body>
      <script type="text/javascript" src="http://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
      <script type="text/javascript">
        $('.copy').click(function () {
            $('.copy-id').select();
            document.execCommand("copy",false,null);
          })
    </script>
    </html>

    这是点击按钮,实现复制

    회신하다
    0
  • PHPz

    PHPz2017-04-11 11:07:56

    <input type="text" id="input">
    <button onclick="copyFn()">点击</button>
    <script>
    function copyFn() {
            var e = document.getElementById("input");
            e.select();
            document.execCommand("Copy");
        }
    </script>

    회신하다
    0
  • 巴扎黑

    巴扎黑2017-04-11 11:07:56

    keydown getSelection

    회신하다
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-11 11:07:56

    见楼上就可以

    회신하다
    0
  • 취소회신하다