Skip to content

Instantly share code, notes, and snippets.

@roshanca
Created October 29, 2020 04:10
Show Gist options
  • Save roshanca/4dcf85dbbf69d338d970fbe536053fea to your computer and use it in GitHub Desktop.
Save roshanca/4dcf85dbbf69d338d970fbe536053fea to your computer and use it in GitHub Desktop.
复制内容至系统剪贴板 #js
export const copyToClip = (text) => {
const input = document.createElement('input')
input.setAttribute('value', text)
input.setAttribute('readonly', 'readonly')
document.body.appendChild(input)
input.select()
try {
document.execCommand('copy')
} catch() {
console.log('无法复制,请手动复制!')
}
document.body.removeChild(input)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment