1. 程式人生 > >clipboard.js-master點選複製到系統剪下板適合移動及PC端

clipboard.js-master點選複製到系統剪下板適合移動及PC端

現代化的“複製到剪下板”外掛。不包含 Flash。gzip 壓縮後僅 3kb。

A modern approach to copy text to clipboard

No Flash. No frameworks. Just 3kb gzipped

Copying text to the clipboard shouldn't be hard. It shouldn't require dozens of steps to configure or hundreds of KBs to load. But most of all, it shouldn't depend on Flash or any bloated framework.

That's why clipboard.js exists.

網盤下載地址:https://pan.baidu.com/s/1x6cD1U5ALiryZkecygOizg

下載後JS放在\clipboard.js-master\dist

使用示例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>target-input</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
    <!-- 1. Define some markup -->
    <input id="foo" type="text" value="hello">
    <button class="btn" data-clipboard-action="copy" data-clipboard-target="#foo">Copy</button>

    <!-- 2. Include library -->
    <script src="../dist/clipboard.min.js"></script>

    <!-- 3. Instantiate clipboard -->
    <script>
    var clipboard = new ClipboardJS('.btn');

    clipboard.on('success', function(e) {
        console.log(e);
    });

    clipboard.on('error', function(e) {
        console.log(e);
    });
    </script>
</body>
</html>

官網:https://clipboardjs.com/

GitHub地址:https://github.com/zenorocha/clipboard.js/