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.endChild(dummy);
dummy.value = text;
dummy.select(); // 选择对象
document.execCommand('copy'); // 执行浏览器复制命令
document.body.removeChild(dummy);
胜象大百科