<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" name="viewport" id="viewport">
<style type="text/css">
</style>
</head>
<body>
<div class="">
<span id="copy_p" style="font-weight:bold;">测试1</span>
<p id="copy">点击复制微信号</p>
</div>
</body>
</html>
<script type="text/javascript">
function copyArticle(event){
const range = document.createRange();
range.selectNode(document.getElementById('copy_p'));
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert('复制成功');
}
document.getElementById('copy').addEventListener('click', copyArticle, false);
</script>
网友评论