使用ZeroClipboard.js复制内容到剪贴板上

1、html

<a id="copyCode">复制</a>

2、初始化

function init(){
var content = "复制的内容";//html的标题:document.title   页面的url:this.location.href
var copyId = "copyCode";//标签的id

var clip = new ZeroClipboard.Client(); // 新建一个对象
clip.setHandCursor( true );
clip.setText(content); // 设置要复制的文本。
clip.addEventListener( "mouseUp", function(client) {
});
// 注册一个 button,参数为 id。点击这个 button 就会复制。
//这个 button 不一定要求是一个 input 按钮,也可以是其他 DOM 元素。
clip.glue(copyId); // 和上一句位置不可调换
}

如果是多个复制,需要初始化多次

原文地址:https://www.cnblogs.com/dongming-03/p/7755024.html