1 Star 0 Fork 16

陈大大 / xe-clipboard

forked from XE / xe-clipboard 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
index.ts 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
xuliangzhan 提交于 2021-06-17 18:11 . fix
'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')
copyElem.blur()
} catch (e) {}
return result
}
/**
* 复制内容到剪贴板
*
* @param {String} content Text 内容
*/
function XEClipboard (content: string | number): boolean {
return copyText(content)
}
XEClipboard.copy = copyText
export default XEClipboard
JavaScript
1
https://gitee.com/c-dada/xe-clipboard.git
git@gitee.com:c-dada/xe-clipboard.git
c-dada
xe-clipboard
xe-clipboard
master

搜索帮助