js实现兼容复制操作

原生js实现复制操作

export const cop = (text) => {
    
    
    if(navigator.clipboard!==undefined) {
    
    
        navigator.clipboard.writeText(text)
    }else {
    
    
        let oInput = document.createElement('input')
        oInput.value = text
        document.body.appendChild(oInput)
        oInput.select()
        document.execCommand('copy')
        oInput.style.display = 'none'
        document.body.removeChild(oInput)
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_53191752/article/details/131007587
今日推荐