js 复制粘贴

input输入框
<div id="top-title" style="position: relative">
<img class="img-responsive center-block" alt="" src="" style="float:left;z-index: 999;position: absolute">
<input type="text" value="" id="awardQqQun1" style="float:left;z-index: 99;position: absolute">
<input type="text" value="" id="awardQqQun2" style="float:left;z-index: 99;position: absolute">
</div>
按钮
<button id="qqQunCopyBtn1" type="button" style="margin-top:5px;">点击复制群号</button>

给button添加一个事件
$("#qqQunCopyBtn1").on('click',function(){
var e=document.getElementById("awardQqQun1");//对象是content
e.select(); //选择对象
document.execCommand("Copy"); //执行浏览器复制命令
alert("群号复制成功");
});

该方法只能复制input里面的内容

原文地址:https://www.cnblogs.com/zxf100/p/8902204.html