📌  相关文章
📜  如何使用 js 启用点击复制功能 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:15.739000             🧑  作者: Mango

代码示例2
var copyTextareaBtn = document.querySelector('.js-textareacopybtn');

copyTextareaBtn.addEventListener('click', function(event) {
  var copyTextarea = document.querySelector('.js-copytextarea');
  copyTextarea.focus();
  copyTextarea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }
});

////html code below