- JS代碼
<script> $(function(){ // 使用outerHTML屬性獲取整個table元素的HTML代碼(包括<table>標簽),然后包裝成一個完整的HTML文檔,設置charset為urf-8以防止中文亂碼 var html = '\<html\>\<head\>\<meta charset="utf-8" \/\>\<\/head\>\<body\>' + document.getElementsByTagName('table')[0].outerHTML + '\<\/body\>\</html\>'; // 實例化一個Blob對象,其構造函數的第一個參數是包含文件內容的數組,第二個參數是包含文件類型屬性的對象 var blob = new Blob([html], { type: "application/vnd.ms-excel" }); var a = document.getElementsByClassName('export')[0]; // 利用URL.createObjectURL()方法為a元素生成blob URL a.href = URL.createObjectURL(blob); // 設置文件名 a.download = "【{$user_name}】提成詳情表.xls"; }) </script>
- 導出按鈕
<a href="" class="export" style="text-decoration: none;display: inline-block;width: 100%;">導出詳情表</a>