Loading

JQ JS复制到剪贴板

示例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script src="clipboard.min.js"></script>
    <!-- Target -->
    <textarea id="bar">Mussum ipsum cacilds...</textarea>
    <!-- Trigger -->
    <button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar">
        Cut to clipboard
    </button>
    <button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js">
    Copy to clipboard
</button>
    <script>
    var clipboard = new ClipboardJS('.btn');
    clipboard.on('success', function(e) {
        console.info('Action:', e.action);
        console.info('Text:', e.text);
        console.info('Trigger:', e.trigger);

        e.clearSelection();
    });

    clipboard.on('error', function(e) {
        console.error('Action:', e.action);
        console.error('Trigger:', e.trigger);
    });
    </script>

</button>

</body>
</html>

如果不需要任何提示这样就可以了

<button class="btn" data-clipboard-text="这里是复制的文本">
    点击复制
</button>

<script>
    new ClipboardJS('.btn');
</script>

下载地址:https://github.com/zenorocha/clipboard.js

posted @ 2018-05-16 18:49  王召波  阅读(211)  评论(0编辑  收藏  举报