zoukankan      html  css  js  c++  java
  • layui 点击链接复制内容到剪切板

    var tableObj = table.render({
                id: 'list_table',
                elem: '#list_table',
                url: '',
                align: "center",
                cols: [[ //表头
                    {type: 'checkbox'},
                    {type: 'numbers', title: '序号',80},
                    {
                        field: 'lock', title: '链接', align: 'center', templet: function (d) {
                        return   '<a href="javascript:;" data-clipboard-text="" class="font-primary" lay-event="share">分享</a>';
                    }, unresize: true, align: 'center'
                    }
                ]]
            });
     table.on('tool(mainList)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'share') {
                      $(".font-primary").attr("data-clipboard-text",data.id);
                      var clipboard = new ClipboardJS('.font-primary');
                      clipboard.on('success', function(e) {
                          alert('复制成功');
                          clipboard.destroy();  //解决多次弹窗
                          e.clearSelection();
                      });
             }
        })

    转载 :https://blog.csdn.net/jia__xin/article/details/89173662

    ---------------------------------------------------------自己项目-----------------------------------------------------------------------------------------

    <script src="/static/clipboard.min.js" charset="utf-8"></script>
    <script src="/static/jquery-3.5.1.min.js" charset="utf-8"></script>
    <script type="text/html" id="titleTpl">
         
          
          {{#  layui.each(d.ip, function(index, item){ }}
      
                <a class="layui-btn layui-btn-normal  font-primary layui-btn-xs data-count-edit"  data-clipboard-text=""  style="background-color: #009688;"  lay-event="share">{{ item.ip }}</a>
          <br>
    
          {{#  }); }}
         
     
    </script>
        {field: 'ip',  160, title: '服务器IP',  templet: '#titleTpl', unresize: true},
     table.on('tool(currentTableFilter)', function (obj) {
            
                var id = obj.data.id;
                var data = obj.data;
             
                if (obj.event === 'edit') {
    
                    var index = layer.open({
                        title: '编辑服务器',
                        type: 2,
                        shade: 0.2,
                        maxmin:true,
                        shadeClose: true,
                        area: ['100%', '100%'],
                        content: "{:url('admin/server/edit')}?id="+id,
                        end: function () {
                            window.location.reload();
                        }
                    });
                    $(window).on("resize", function () {
                        layer.full(index);
                    });
                    return false;
                }else if (obj.event === 'share') {
                    //复制粘贴
                  var text =  $(this).text();
                  
                    $(".font-primary").attr("data-clipboard-text",text);
                     var clipboard = new Clipboard('.font-primary');
                    
                    clipboard.on('success', function(e) {
                        layer.msg('复制成功');
                        // alert('复制成功');
                        clipboard.destroy();  //解决多次弹窗
                        e.clearSelection();
                    });
                } else if (obj.event === 'delete') {
                    layer.confirm('真的删除行么', function (index) {
                        obj.del();
                        layer.close(index);
                        $.ajax({
                            type:'post',
                            url:"{:url('admin/server/del')}",
                            data:{id:obj.data.id},
                            success:function (res) {
                               // console.log(res);
                                if (res.status == 200) {
                                    layer.msg(res.msg,{time: 500},function () {
                                        window.location.reload();
                                    })
                                } else {
                                    layer.msg('失败', {icon: 2, time: 500},function () {
                                        window.location.reload();
                                    });
                                }
                            }
                        });
                    });
                }
            });
  • 相关阅读:
    Ubuntu 12.04 安装scribe 的笔记 | 动漫驿站
    boost install on prinse 12.04 ubuntu
    basic coder » linux下获取当前程序的绝对路径
    spring 使用 groovy 的 utf8 问题
    string转化大小写(C++) | Vimer的程序世界
    linux常用命令一
    STL map与Boost unordered_map 有何不可的日志 网易博客
    本博使用的vim(gvim)相关插件整理
    【转】C++11中值得关注的几大变化 奔向C++ C++博客
    Lua 语言和C/C++集成调研小结
  • 原文地址:https://www.cnblogs.com/yehuisir/p/14009752.html
Copyright © 2011-2022 走看看