1 export const copy = (text) => { 2 const textArea = document.createElement('textarea'); 3 4 textArea.style.position = 'fixed'; 5 textArea.style.top = '0'; 6 textArea.style.right = '0'; 7 8 textArea.style.width = '2em'; 9 textArea.style.height = '2em'; 10 11 render. 12 textArea.style.padding = '0'; 13 14 textArea.style.border = 'none'; 15 textArea.style.outline = 'none'; 16 textArea.style.boxShadow = 'none'; 17 18 textArea.style.background = 'transparent'; 19 20 textArea.value = text; 21 document.body.appendChild(textArea); 22 23 textArea.select(); 24 25 let result = false; 26 try { 27 result = !!document.execCommand('copy'); 28 } catch (err) { 29 // do nothing 30 } 31 32 document.body.removeChild(textArea); 33 return result; 34 };
标签:none,document,textArea,style,result,copy From: https://www.cnblogs.com/lrtroot/p/16785310.html