首页 > Web开发 > 详细

jquery非文本框复制

时间:2018-09-16 11:45:01      阅读:212      评论:0      收藏:0      [点我收藏+]
        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);

 

jquery非文本框复制

原文:https://www.cnblogs.com/romanticcrystal/p/9655063.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!