1. 程式人生 > >js複製內容,相容所有瀏覽器

js複製內容,相容所有瀏覽器

大概思路:

創造一個新的節點,用完後刪除

var oInput = document.createElement('input');
oInput.value = '複製內容';
document.body.appendChild(oInput);
oInput.select();//選擇物件
document.execCommand('copy');//執行瀏覽器複製命令
document.body.removeChild(oInput);