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

7次阅读

共计 350 个字符,预计需要花费 1 分钟才能阅读完成。

方法 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);

正文完
 0