美文网首页
document.execCommand实现复制

document.execCommand实现复制

作者: chenjundi | 来源:发表于2019-10-23 16:38 被阅读0次

    使用一个不展示的input标签来模拟复制功能,参考 document.execCommand

    function copyUrl() {
      var URL = Math.random();
      console.log(URL);
      var oInput = document.createElement('input');
      oInput.value = URL;
      document.body.appendChild(oInput);
      oInput.select();
      document.execCommand("Copy");
      oInput.remove();
    }
    

    现在去调用这个copyUr函数,找个地方ctr+v看看效果吧。

    相关文章

      网友评论

          本文标题:document.execCommand实现复制

          本文链接:https://www.haomeiwen.com/subject/paukvctx.html