zoukankan      html  css  js  c++  java
  • 跨浏览器的复制文本功能

    js控件地址:https://github.com/zeroclipboard/zeroclipboard

    指令说明:https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md

    注意:这个复制功能只能放在服务器上才有用,因为swf有domain的控制trustedDomains 设置.

    <html>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <body>
            <!--data-clipboard-target指定复制的数据源为ID为spanBox的元素-->
            <button id="btnCopy" data-clipboard-target="spanBox">点我复制</button>
            <span id="spanBox">哎呀被点到了</span>
            <script src="ZeroClipboard.min.js"></script>
            <script>
                function copyString(strBtnId) {
                    //针对ie6
                    if ($.browser.version == 6.0) {
                        $('#' + strBtnId).bind("click", function() {
                            strDomId = $(this).attr('data-clipboard-target');
                            window.clipboardData.setData("Text", $('#' + strDomId).val());
                            alert('复制成功');
                        })
                        return;
                    }
    
                    var config = {
                        moviePath: "http://img1.tiancitycdn.com/mh/homepage/js/ZeroClipboard20140122.swf",
                        forceHandCursor: true, //复制按钮手型提示
                        debug: false //发送控制台消息
                    };
                    var client = new ZeroClipboard(document.getElementById(strBtnId), config);
                    client.on("load", function(client) {
                        client.on("complete", function(client, args) {
                            alert('复制成功');
                        });
                    });
                }
    
                (function() {
                    copyString('btnCopy');
                })();
            </script>
        </body>
    </html>
  • 相关阅读:
    mem系函数总结
    shell----删除文件中的^M
    为tcp的connect设置超时时间
    ue-edit设置显示函数列表
    bep-10翻译
    mysql--慢查询,卡死等处理
    mongodb---js脚本操作速记
    佛主保佑,永无bug
    【php】中【event】之实现方式
    BI任务列表
  • 原文地址:https://www.cnblogs.com/bossikill/p/3528505.html
Copyright © 2011-2022 走看看