html:
<div style="height:0px; text-indent:-10000px;"><span id="hdcopyurl" style="">http://www.baidu.com</span></div>
<a onClick="copyUrl()" style="cursor: pointer;">复制链接</a>
js:
<script>
function copyUrl() {
var clipBoardContent = document.getElementById("hdcopyurl");
window.getSelection().selectAllChildren(clipBoardContent);
document.execCommand("Copy");
alert('复制成功');
}
</script>
参考:https://www.cnblogs.com/MythLeige/p/9110621.html