itools.js
Version:
前端开发中常用的工具方法
21 lines (20 loc) • 397 B
JavaScript
/**
* 复制内容到剪贴板
* @param {*} text
*/
const copy = (text) => {
let input = document.createElement('input')
input.style.position = 'absolute'
input.style.opacity = 0
input.value = text
let res = true
try {
input.select()
document.execCommand('Copy')
} catch (e) {
res = false
}
document.body.appendChild(input)
return res
}
export default copy