封装剪贴板:
function Copy(str) {
var save = function (e) {
//设置需要复制模板的内容
e.clipboardData.setData(\'text/plain\',str);
//阻止默认行为
e.preventDefault();
}
// h5监听copy事件,调用save函数保存到模板中
document.addEventListener(\'copy\',save);
// 调用右键复制功能
document.execCommand(\'copy\');
//移除copy事件
document.removeEventListener(\'copy\',save);
alert("复制成功");
}
点击调用函数
$(\'.CopeBorder\').on(\'click\',function () {
var CopeBorder=$(".CopeText").text();
// console.log(typeof CopeBorder)
Copy(CopeBorder);
})