1. 引入js文件
 
<script src="dist/clipboard.min.js"></script>

  

  1. 绑定
            (1)data-clipboard-action属性
                默认值是copy,也就是复制功能,也可以为cut(剪切)
            (2)data-clipboard-target属性
                要复制的目标值
                
 
<input >
 
 
<button class="btn" data-clipboard-target="#foo"> <img src="assets/clippy.svg" alt="Copy to clipboard"> </button>

  

 
JS引入clipboard.js,实现复制功能
 
            (3)data-clipboard-text属性
                不需要其他元素就能从目标属性复制的内容
<button class="btn" data-clipboard-text="111122222"> Copy to clipboard </button>

  

 
  1. 事件(成功和失败事件)
var clipboard = new ClipboardJS('.btn'); 
clipboard.on('success', function(e) { 
    console.info('Action:', e.action); 
    console.info('Text:', e.text); 
    console.info('Trigger:', e.trigger); 
    e.clearSelection(); 
}); 
clipboard.on('error', function(e) { 
    console.error('Action:', e.action); 
    console.error('Trigger:', e.trigger); 
});

 

 
JS引入clipboard.js,实现复制功能
 
 
 
 
 
 
 
 
 
 

相关文章:

  • 2022-12-23
  • 2021-06-01
  • 2021-07-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2021-10-15
  • 2022-12-23
相关资源
相似解决方案