HTML
<div class="userTitle">
<h1 id="userName">油菜花花匠</h1>
<p>邀请码:<span id="code">8975341</span><i onclick="copyText()">复制</i></p>
<textarea id="container"></textarea>
</div>
CSS
.userImg img{
width: 2.2666666666666666rem;
height: 2.2666666666666666rem;
}
.userTitle{
width: 5.866666666666666rem;
position: absolute;
top: 0.88rem;
left: 3.066666666666667rem;
}
.userTitle #container{
position: absolute;
top: 0;
left: 0;
opacity: 0;
z-index: -10;
background-color: rgba(0,0,0,0.0);
border: none;
width: 0.013333333333333334rem;
height: 0.013333333333333334rem;
}
JS
//copy邀请码
function copyText(){
var text = $_("code").innerHTML;
$_("container").value = text;
$_("container").select();
document.execCommand("copy");
alert("已复制");