码迷,mamicode.com
首页 > Web开发 > 详细

js拷贝指定内容到剪切板

时间:2017-07-10 14:24:49      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:sel   keyword   var   board   back   clip   com   str   oar   

 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);}

js拷贝指定内容到剪切板

标签:sel   keyword   var   board   back   clip   com   str   oar   

原文地址:http://www.cnblogs.com/zinan/p/7145212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!