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的内容')