移动端点击按钮复制文本内容,具体内容如下所示:
<div> <p>邀请码</p> // <p id="inviteCode" class="inviteCode">{{invite_code}}</p> <input id="inviteCode" class="inviteCode" type="text" /> <p class="copy">复制</p> </div> copy() { var Url2 = this.invite_code; //var oInput = document.createElement("input"); var oInput = document.getElementById("inviteCode"); //oInput.value = Url2; // document.body.appendChild(oInput); oInput.select();// 选择对象 //document.execCommand("Cut","false",null);// 执行浏览器剪切命令 document.execCommand("Copy");// 执行浏览器复制命令 //oInput.className = "oInput"; //oInput.style.display = "none"; alert("复制成功"); //console.log(document.execCommand("Copy")) },