2026/1/23 23:00:41
网站建设
项目流程
网站建设龙头股,哪里有网站建设工程,平谷网站建设,手机企业wap网站实现一个具有复制功能的文字按钮 通过点击按钮实现指定文字的复制功能。 文章目录1.效果图2.关键代码总结1.效果图 2.关键代码
#template
span idcopycontent{{web_url}}/spanbutton styleposition: relative; top: -2px;left: 5px;spanidcopycontent{{web_url}}/spanbuttonstyleposition:relative;top:-2px;left:5px;varianttextthemesuccessclickcopyClick复制/button#script methods:{copyClick(){varinputdocument.createElement(input);document.body.appendChild(input);varcontentdocument.querySelector(#copycontent).innerHTML;input.setAttribute(value,content);input.select();if(document.execCommand(copy)){document.execCommand(copy);this.$message.success(this.$t(copy_succ));}document.body.removeChild(input);},}总结通过操作DOM 使用 document.execCommand(‘copy’) 是用于复制选中文本到剪贴板的命令。但是document.execCommand 存在兼容性问题部分浏览器可能已经不再支持。