Yjjhn
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <div class="u_div"> <span>微信</span>
        <div id="wxnum">123456</div>
        <a href="javascript:void(0);" id="copyBtn">复制</a>
    </div>
</body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
function copyArticle(event) {
    const range = document.createRange();
    range.selectNode(document.getElementById(\'wxnum\'));
    const selection = window.getSelection();
    if(selection.rangeCount > 0) selection.removeAllRanges();
    selection.addRange(range);
    document.execCommand(\'copy\');
    alert("复制成功!");
  }
document.getElementById(\'copyBtn\').addEventListener(\'click\', copyArticle, false);
</script>
</html>

 

分类:

技术点:

相关文章:

  • 2021-11-22
  • 2021-08-20
  • 2021-06-29
  • 2021-04-07
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-16
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2021-11-07
  • 2021-10-18
  • 2022-12-23
相关资源
相似解决方案