zoukankan      html  css  js  c++  java
  • 点击某个内容复制到粘贴板

    <!DOCTYPE html>

    <head>
    <title>中英文切换</title>
    <meta charset="UTF-8"/>
    <script type="text/javascript" src="jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="language.js"></script>
    </head>

    <body>
    <table id="data">
    <tr>
    <td class="copyable"> 姓名:</td>
    <td class="copyable">张三</td>
    </tr>
    <tr>
    <td> 年龄:</td>
    <td>18</td>
    </tr>
    <tr>
    <td class="copyable"> 性别:</td>
    <td class="copyable">男</td>
    </tr>
    </table>
    <br>
    <p class="copy">copy</p>
    <p class="copy">copy2</p>
    <br>
    <div id="copy-temp"></div>
    </body>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(".copy").click(function () {
    var $o = $("<textarea rows='10' cols='50'>");
    $o.val($(this).text())//填充要复制的文字
    $("#copy-temp").append($o)
    if (copy($o[0])) {
    $o.remove()
    alert("复制成功!");
    } else {
    alert("复制失败,请手动复制");
    }
    })

    function copy(obj) {
    obj.select();
    try {
    if (document.execCommand('copy', false, null)) {
    document.execCommand("Copy");
    return true;
    }
    } catch (err) {

    }
    return false;
    }
    </script>
  • 相关阅读:
    [LuoGu] P1004 方格取数
    [LuoGu] P1018 乘积最大
    [LuoGu] P2758 编辑距离
    [JZOJ] 01知多少
    [LuoGu] P1731 生日蛋糕
    $mathcal{Const,Inline,Register}$用法总结
    T2027 蜈蚣
    T57274 黑暗城堡
    P2312 解方程
    AT2412 最大の和
  • 原文地址:https://www.cnblogs.com/duanpengpeng/p/11149356.html
Copyright © 2011-2022 走看看