js复制内容到剪贴板
复制内容到剪贴板,亲测有效,ios和安卓都适用
代码如下:
copy(content){
// content为要复制的内容
// 创建元素用于复制
const ele = document.createElement('input')
// 设置元素内容
ele.setAttribute('value', content)
// 将元素插入页面进行调用
document.body.appendChild(ele)
// 复制内容
ele.select()
// 将内容复制到剪贴板
document.execCommand('copy')
// 删除创建元素
document.body.removeChild(ele)
alert('复制成功');
},