""<span style="font-size: 14px;color:#AAAAAA;float: right;" id="copy">
                                                    被复制的信息
</span>"""


function copyAction(event) {
const range = document.createRange();
range.selectNode(document.getElementById('copy'));
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert("复制成功!");
}

document.getElementById('copy').addEventListener('click', copyAction, false);































转载链接:https://blog.csdn.net/cxwtsh123/article/details/80974904