1、html页面代码
<span id="dd">www.baidu.com</span>
<button id="click_aa" onclick="myfun()">点击复制</button>
2、js代码
<script type="text/javascript">
function myfun(){
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');
alert('success');
}
</script>
function myfun(){
var txt = document.getElementById('dd').select();
document.execCommand('copy');
}