js 复制文本到剪贴板

  var str = "博客园最棒!";   var tempInput = document.createElement('input');   tempInput.value = Url2;   document.body.appendChild(tempInput);   tempInput.select(); // 选择对象   document.execCommand("Copy"); // 执行浏览器复制命令   tempInput.className = 'tempInput';   tempInput.style.display='none';   document.body.removeChild("tempInput");

  “博客园最棒!”

  比如把这句话复制到剪贴板

  var str = "博客园最棒!";

  var tempInput = document.createElement('input');

  tempInput.value = Url2;

  document.body.appendChild(tempInput);

  tempInput.select(); // 选择对象

  document.execCommand("Copy"); // 执行浏览器复制命令

  tempInput.className = 'tempInput';

  tempInput.style.display='none';

  document.body.removeChild("tempInput");

猜你喜欢

转载自www.cnblogs.com/hill-foryou/p/9025214.html