function copyTextToClipboard(text) {  
  var textArea = document.createElement("textarea");   
  textArea.style.background = 'transparent';  
  textArea.value = text;  
  document.body.appendChild(textArea);  
  textArea.select();  
  try {    
    var successful = document.execCommand('copy');    
    var msg = successful ? 'successful' : 'unsuccessful';          
  } catch (err) {  
  console.log('Oops, unable to copy');  
  }  
 document.body.removeChild(textArea);}
posted on 2017-07-10 12:31  芝麻的西瓜  阅读(244)  评论(0编辑  收藏  举报