1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > JS复制文本到剪切板

JS复制文本到剪切板

时间:2023-11-09 15:05:22

相关推荐

JS复制文本到剪切板

// 是否支持复制 export const isSupportCopy = ((!!document.queryCommandSupported) && document.queryCommandSupported('copy')); const copyTempElement = document.createElement('textarea'); copyTempElement.setAttribute('style', 'margin:0;padding:0;width:0;height:0;position:absolute;'); document.body.appendChild(copyTempElement); // 复制文本到剪切板 export function copyText(text) { let succeeded; try { copyTempElement.value = text; copyTempElement.select(); succeeded = document.execCommand('copy'); } catch (err) { succeeded = false; } return succeeded; }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。