本文介绍: 【代码】js实现 copy字符串 复制到剪切板。

  • 定义方法
function copyStr(str) {
   var oInput = document.createElement('input');
   oInput.value = str;
   document.body.appendChild(oInput);
   oInput.select(); // 选择对象
   document.execCommand('Copy'); // 执行浏览器复制命令
   oInput.className = 'oInput';
   oInput.style.display = 'none';
}
  • 调用方法
copyStr('要copy的内容')

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注