js-实现复制功能的两种方法

方法1:

var oInput = document.getElementById('input');
oInput.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
message.success("复制成功", 1);

方法2:

var dummy = document.createElement('input');
text = window.location.href;
document.body.appendChild(dummy);
dummy.value = text;
dummy.select(); // 选择对象
document.execCommand('copy'); // 执行浏览器复制命令
document.body.removeChild(dummy);

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理