js 实现粘贴板功能

  • js代码
 function copyLink(){
        // 复制关键字
        var oInput = document.createElement('input');
        oInput.value = '这里是简要复制的内容。。。。';
        document.body.appendChild(oInput);
        oInput.select(); // 选择对象
        document.execCommand("Copy"); // 执行浏览器复制命令
        oInput.className = 'oInput';
        oInput.style.display='none';
        
        console.log( oInput.value);
    }
  • html
<button type="button" class="copy-link" onclick="copyLink(this)">复制链接</button>

你可能感兴趣的:(javascript)