欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js+html5實(shí)現(xiàn)復(fù)制文字按鈕

 更新時(shí)間:2017年07月15日 15:18:07   作者:ouqi_qiou  
這篇文章主要為大家詳細(xì)介紹了js+html5實(shí)現(xiàn)復(fù)制文字按鈕,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js+html5實(shí)現(xiàn)點(diǎn)擊復(fù)制文字的按鈕,供大家參考,具體內(nèi)容如下

圖片展示:

注意css中的樣式,有些頁面復(fù)制不成功就是沒有添加那一句造成的。

代碼塊

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>

  <style type="text/css">
    *{
      -webkit-user-select: auto;
    }
  </style>

  <body>
    <span id="content">
      你好,好久不見!
    </span>
    <button id="copyBT">復(fù)制</button>
    <script>
      function copyArticle(event) {
        const range = document.createRange();
        range.selectNode(document.getElementById('content'));

        const selection = window.getSelection();
        if(selection.rangeCount > 0) selection.removeAllRanges();
        selection.addRange(range);
        document.execCommand('copy');
        alert("復(fù)制成功!");
      }

      document.getElementById('copyBT').addEventListener('click', copyArticle, false);
    </script>
  </body>

</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論