js一键复制到剪切板

时间:2021-09-07 16:22:48   收藏:0   阅读:20

 

function copy() {
    let transfer = document.createElement(input);
    document.body.appendChild(transfer);
    transfer.value = 这里是想要复制的内容; 
    transfer.focus();
    transfer.select();
    if (document.execCommand(copy)) {
        document.execCommand(copy);
    }
    transfer.blur();
    console.log(复制成功);
    document.body.removeChild(transfer);
}

 

原文:https://www.cnblogs.com/xym0710/p/15235327.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!