JQ JS複製到剪貼板

示例:html

<!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>

若是不須要任何提示這樣就能夠了git

<button class="btn" data-clipboard-text="這裏是複製的文本">
    點擊複製
</button>

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

下載地址:https://github.com/zenorocha/clipboard.jsgithub

相關文章
相關標籤/搜索