javascript - js实现ctrl + c 的复制功能?
迷茫
迷茫 2017-04-11 11:05:56
0
4
1087

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

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

Antworte allen(4)
刘奇
<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>

这是点击按钮,实现复制

PHPzhong
<input type="text" id="input">
<button onclick="copyFn()">点击</button>
<script>
function copyFn() {
        var e = document.getElementById("input");
        e.select();
        document.execCommand("Copy");
    }
</script>
巴扎黑
keydown getSelection
伊谢尔伦

见楼上就可以

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!