js复制文字的方法
function copyText(text){ var textValue = document.createElement('textarea'); textValue.setAttribute('readonly', 'readonly'); //设置只读属性防止手机上弹出软键盘 textValue.value = text; document.body.appendChild(textValue); //将textarea添加为body子元素 textValue.select(); var res = document.execCommand('copy'); document.body.removeChild(textValue);//移除DOM元素 console.log("复制成功"); return res; }
js复制文字的方法
如果遇到什么不懂的地方直接关注公众号留言(本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。)
作者:newmiracle
出处:https://www.cnblogs.com/newmiracle/