复制文字或图片
作者:
红酒煮咖啡 | 来源:发表于
2022-03-07 17:24 被阅读0次import { message } from 'antd'
export const copyText = (type, content) => {
//type==''div"||"img" 文字传div
const div = document.createElement(type)
type == 'img' ? (div.src = content) : (div.innerHTML = content)
document.getElementById('app').appendChild(div)
window.getSelection().removeAllRanges()
const range = document.createRange()
window.getSelection().addRange(range)
range.selectNode(div)
document.execCommand('copy')
message.success(type == 'img' ? '图片复制成功' : '文本复制成功')
div.remove()
window.getSelection().removeAllRanges()
}
本文标题:复制文字或图片
本文链接:https://www.haomeiwen.com/subject/cmynrrtx.html
网友评论