原生js复制方法


const copyText = (text, callback) => { // text: 要复制的内容, callback: 回调
        var tag = document.createElement('input');
        tag.setAttribute('id', 'copy_input');
        tag.value = text;
        document.getElementsByTagName('body')[0].appendChild(tag);
        document.getElementById('copy_input').select();
        document.execCommand('copy');
        document.getElementById('copy_input').remove();
        if(callback) {callback(text)}
}