<!DOCTYPE html>
<html lang="en">
<head>
<style>
.copy-link{width:90px;height:30px;background:#FF0000;margin:15px auto 0;font-size: 15px;color:#FFFFFF;line-height: 30px;text-align: center;cursor:pointer;border-radius:25px; display:inline-block;}
.link-box{display:inline-block;}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="link-box" id="link-box" >https://www.suansuanru.cc/s/iPgQp</div>
<div onselectstart="return false" class="copy-link" >复制链接</div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.0/jquery.js"></script>
<script src="clipboard.js"></script>
<script>
$('.copy-link').click(function(){
copyTxt('link-box');
});
// 复制功能
function copyTxt(con) {
const range = document.createRange();
range.selectNode(document.getElementById(con));
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert("复制成功!");
}
</script>
</html>
function copyTxt(con) {
const range = document.createRange();
range.selectNode($('#'+con)[0];
const selection = window.getSelection();
if(selection.rangeCount > 0) selection.removeAllRanges();
selection.addRange(range);
document.execCommand('copy');
alert("复制成功!");
}