js复制文本到剪贴板,兼容ios,Android

// 复制到剪切板
document.querySelector(".copylink").addEventListener('click', copyArticle, false);
function copyArticle() {
    const range = document.createRange();
    range.selectNode(document.querySelector(".copy_txt"));
    const selection = window.getSelection();
    if(selection.rangeCount > 0) selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand('Copy');
    alert("复制成功!");
}

 

上一篇:Demo:选择屏幕写页签


下一篇:2021-01-20