H5就是移动端的web页面,现在可以说是非常的流行!今天就把我用H5实现复制粘贴功能分享出来给大家吧!
方案一 : 可满足大部分浏览器正常使用!
copy exampleCopy
var copyBtn = document.querySelector('.copy')
// 点击的时候调用 copyTextToClipboard() 方法就好了.
copyBtn.onclick = function() {
copyTextToClipboard('随便复制点内容试试')
}
function copyTextToClipboard(text) {
var textArea = document.createElement("textarea")
textArea.style.position = 'fixed'
textArea.style.top = 0
textArea.style.left = 0
textArea.style.width = '2em'
textArea.style.height = '2em'
textArea.style.padding = 0
textArea.style.border = 'none'