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);}
时间: 2024-10-12 12:32:11