클립보드 내용 복사

9568 단어 Html

프런트엔드 코드

<div class="feed-element">
  <div class="media-body ">
      <p>
           
      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 >

좋은 웹페이지 즐겨찾기