js 實現複製功能的兩種方法

方法1:瀏覽器

var oInput = document.getElementById('input');
oInput.select(); // 選擇對象
document.execCommand("Copy"); // 執行瀏覽器複製命令
message.success("複製成功", 1);

方法2:app

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);
相關文章
相關標籤/搜索