jq 点击文本复制

<a title="<?= $u['did']; ?>" id="article">
     <div class="td-text" id="copy-text"><?= $u['did']; ?></div>
</a>
 $(document).on('click', '#article', function() {
        const range = document.createRange();
        range.selectNode($(this)[0]);//点击选择的文本
        const selection = window.getSelection();
        if (selection.rangeCount > 0) selection.removeAllRanges();
        selection.addRange(range);
        document.execCommand('copy');
    });
posted @ 2022-10-18 15:03  陈陈陈在成长  阅读(270)  评论(0)    收藏  举报