Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
index.ts 1017 Bytes
Copy Edit Raw Blame History
'use strict'
var doc = window.document
var copyElem: HTMLTextAreaElement
function handleText (content: string | number) {
if (!copyElem) {
copyElem = doc.createElement('textarea')
copyElem.id = '$XECopy'
var styles = copyElem.style
styles.width = '48px'
styles.height = '24px'
styles.position = 'fixed'
styles.zIndex = '0'
styles.left = '-500px'
styles.top = '-500px'
doc.body.appendChild(copyElem)
}
copyElem.value = content === null || content === undefined ? '' : ('' + content)
}
function copyText (content: string | number): boolean {
var result = false
try {
handleText(content)
copyElem.select()
copyElem.setSelectionRange(0, copyElem.value.length)
result = doc.execCommand('copy')
} catch (e) {}
return result
}
/**
* 复制内容到剪贴板
*
* @param {String} content Text 内容
*/
function XEClipboard (content: string | number): boolean {
return copyText(content)
}
XEClipboard.copy = copyText
export default XEClipboard
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化