zoukankan      html  css  js  c++  java
  • 一款给力的一键复制js插件-clipboard.js

    一款没有依赖的、给力的一键复制的JS插件   点我前往github

    案例demo见下载包内demo文件夹。

    这里晒出最常用的几种方式,以供不时之需。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>function-target</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <!-- 1. Define some markup -->
        <button class="btn">Copy</button>
        <div>hello</div>
    
        <!-- 2. Include library -->
        <script src="../dist/clipboard.min.js"></script>
    
        <!-- 3. Instantiate clipboard -->
        <script>
        var clipboard = new ClipboardJS('.btn', {
            target: function() {
                return document.querySelector('div');
            }
        });
    
        clipboard.on('success', function(e) {
            //console.log(e);
            alert('复制成功!')
        });
    
        clipboard.on('error', function(e) {
            console.log(e);
        });
        </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>function-text</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <!-- 1. Define some markup -->
        <button class="btn">Copy</button>
    
        <!-- 2. Include library -->
        <script src="../dist/clipboard.min.js"></script>
    
        <!-- 3. Instantiate clipboard -->
        <script>
        var clipboard = new ClipboardJS('.btn', {
            text: function() {
                return 'to be or not to be';
            }
        });
    
        clipboard.on('success', function(e) {
            console.log(e);
        });
    
        clipboard.on('error', function(e) {
            console.log(e);
        });
        </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>target-div</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <!-- 1. Define some markup -->
        <span class="copy_content">hello 123</span>
        <button class="btn" data-clipboard-action="copy" data-clipboard-target=".copy_content">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>
    <!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>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>target-textarea</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <!-- 1. Define some markup -->
        <textarea id="bar">hello</textarea>
        <button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar">Cut</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>
  • 相关阅读:
    Golang之字符串格式化
    BZOJ 4513: [Sdoi2016]储能表 [数位DP !]
    BZOJ 3329: Xorequ [数位DP 矩阵乘法]
    BZOJ 1833: [ZJOI2010]count 数字计数 [数位DP]
    HDU2089 不要62 BZOJ1026: [SCOI2009]windy数 [数位DP]
    未完
    [Miller-Rabin & Pollard-rho]【学习笔记】
    BZOJ 3551: [ONTAK2010]Peaks加强版 [Kruskal重构树 dfs序 主席树]
    BZOJ 3123: [Sdoi2013]森林 [主席树启发式合并]
    BZOJ 3545: [ONTAK2010]Peaks [Splay启发式合并]
  • 原文地址:https://www.cnblogs.com/phper12580/p/9856177.html
Copyright © 2011-2022 走看看