jquery非文本框复制

复制代码
        function selectText(x) {
            if (document.selection) {
                var range = document.body.createTextRange();//ie
                range.moveToElementText(x);
                range.select();
            } else if (window.getSelection) {
                var selection = window.getSelection();
                var range = document.createRange();
                selection.removeAllRanges();
                range.selectNodeContents(x);
                selection.addRange(range);
            }
        }
        function cp(x) {
            selectText(x);
            document.execCommand("copy");
            layer.msg("已复制");
        }
        function gettxt(obj) {
            show(obj);
        }
        function show(txt) {
                layer.open({
                    type: 1,
                    title: "URL",
                    closeBtn: 0,
                    shadeClose: true,
                    skin: 'yourclass',
                    area: ['30%', 'auto'],
                    content: "<p onclick='cp(this);'>"+txt+"</p>"
                });
        }
复制代码

使用方法:
直接在要复制的标签上添加click事件

  onclick="gettxt($(this).attr('title'));"

 

onclick='cp(this);'

 

posted @   大da脸  阅读(322)  评论(0编辑  收藏  举报
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
点击右上角即可分享
微信分享提示