js复制文字到剪切板

 document.getElementById('copy').onclick = function () {
      let input = document.createElement('input');
      input.setAttribute('id','input');
      input.value = 'hello';
      document.getElementsByTagName('body')[0].appendChild(input);
      document.getElementById('input').select();
      document.execCommand('copy');
      document.body.removeChild(input);
    }

 

posted @ 2021-03-12 18:36  ltog  阅读(54)  评论(0编辑  收藏  举报