JS 将字符串复制到剪切板


function copyText(text)
{
    var input = document.createElement('input');
    
    input.setAttribute('id', 'input_for_copyText');
    input.value = text;
    
    document.getElementsByTagName('body')[0].appendChild(input);
    document.getElementById('input_for_copyText').select();
    document.execCommand('copy');
    document.getElementById('input_for_copyText').remove();
}
posted @ 2020-12-10 11:09  何效名  阅读(1733)  评论(0编辑  收藏  举报