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

一、htmlhtml

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

 

二、初始化url

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); // 和上一句位置不可调换
}htm

 

 

若是是多个复制,须要初始化屡次对象

相关文章
相关标签/搜索