1. 程式人生 > >移動端、pc端通用點選複製

移動端、pc端通用點選複製


點選複製


function copyArticle(event){
    const range = document.createRange();
    range.selectNode(document.getElementById('dd'));
    const selection = window.getSelection();
    if(selection.rangeCount > 0) selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand('copy');
    $(this).text("已複製");
    setTimeout(function(){$("#cp1").text("點選複製")},1000);
}
document.getElementById('cp1').addEventListener('click', copyArticle, false);