欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

复制到剪切板

程序员文章站 2022-05-15 23:14:14
...

html

      <div class="cl copye_div">
        <div class="left copybtn" id="copyqq" data-clipboard-action="copy" data-clipboard-target="div"
          data-clipboard-text="2305731027">

        </div>
        <div class="left copytitle">
          QQ:
        </div>
        <div class="left" id="qq">
          2305731027
        </div>
      </div>

地址链接

https://clipboardjs.com/
  <script src="./js/jquery-3.5.1.min.js"></script>
  <script src="./js/clipboard.min.js"></script>

JS:

 $(document).ready(function () {
    var clipboard = new ClipboardJS('#copyqq');

    clipboard.on('success', function (e) {
      console.log('Action:', e);

      e.clearSelection();
    });

    clipboard.on('error', function (e) {
      console.log(e)
    });


    var clipboard = new ClipboardJS('#copytelegram');

    clipboard.on('success', function (e) {
      console.log('Action:', e);

      e.clearSelection();
    });

    clipboard.on('error', function (e) {
      console.log(e)
    });
    var clipboard = new ClipboardJS('#copyskype');

    clipboard.on('success', function (e) {
      console.log('Action:', e);

      e.clearSelection();
    });

    clipboard.on('error', function (e) {
      console.log(e)
    });
  })
相关标签: JS