1 引用jquery
<script src="https://cdn.bootcss.com/jquery/1.11.2/jquery.js"></script>
<div id='box'>我的清华大学好好哈</div>
//注意:利用input临时保存值实现, type="hidden"无法保存值
<input type="text" id="copy-text" style="position: fixed; top: -9999px; left: 0; z-index: 9999;">
<span id="copy" data-text="我的清华大学好好哈">复制</span>
<script>
//复制编号
function copyHandler(me) {
var _this = me;
var copyText = $("#copy-text");
copyText.val($(_this).attr("data-text"));
copyText.select();
document.execCommand("Copy");
}
$("#copy").on("click",function(){
var _this = this;
copyHandler(_this);
});
</script>