js 复制到剪贴板

2021-08-14 10:04  787人阅读  评论 (0)
Tags: js

js 复制到剪贴板

function copy2clipboard(text) {
    if (navigator.clipboard) {
        return navigator.clipboard.writeText(text);
    }
    var input = document.createElement('input');
    input.style.width = '1px';
    input.style.height = '1px';
    input.style.border = 0;
    input.style.outline = 0;
    input.style.bottom = 1;
    input.style.right = 1;
    input.style.position = 'fixed';
    input.value = text;
    document.body.appendChild(input);
    input.select();
    document.execCommand('copy');
    document.body.removeChild(input);
    return true;
}





豫ICP备09035262号-1