clipboard 复制内容

前端代码

<div class="feed-element">
  <div class="media-body ">
      <p>
        需要复制的内容 &nbsp;
      </p>
      <div class=" pull-right">
           <button class="btn btn-success btn-sm btn-circle btn-outline copy_write tips-layui" data-clipboard-text="" type="button"  data-tip="复制历史写作内容" ><i class="fa fa-copy " ></i></button>
       </div>
    </div>
</div>

js 代码

//引入clipboard.min.js文件
<script type="text/javascript" src="https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.min.js"></script>
<script >
    /**
     * ContentReplication
     */
    $(".copy_write").click(function () {
        let val=$(this).parent().siblings("p").text();
        let ok_val=val.trim();
       $(this).attr("data-clipboard-text",ok_val);
    });
    // copy
    var clipboard = new ClipboardJS('.copy_write');
    clipboard.on('success', function (e) {
        e.clearSelection();
        layer.msg('写作内容已复制', {icon: 1,time:1000});
    });
    clipboard.on('error', function (e) {
        layer.msg('复制失败,请手动复制', {icon: 2,time:1000});
    });
</script >

评论

(= ̄ω ̄=)··· 暂无内容!

回复

您还未登录,请先登录或者注册