<input id="Button1" type="button" value="导出EXCEL" onclick="copyToClipboard(‘ta‘)">
<div style="width: 760px;float:left;" id="ta">
<table border="0" style="" cellpadding="3" cellspacing="1" width="760">
</table>
</div>
<script src="https://cdn.bootcss.com/jquery/1.12.3/jquery.min.js"></script>
<script>
function copyToClipboard(elementId) {
var aux = document.createElement("input");
var $a = $(‘#‘+elementId).clone();
$a.find(‘input‘).each(function(){
var x = $(this).val();
$(this).parent().html(x);
});
aux.setAttribute("value", $a.html());
document.body.appendChild(aux);
aux.select();
document.execCommand("copy");
document.body.removeChild(aux);
alert("复制成功");
}
</script>
原文地址:https://www.cnblogs.com/zhaoxiangshang/p/11783014.html