demo代码如下:
<div class="row"> <div class="col-lg-12"> <div> <button class="btn btn-primary" type="button" onclick="export2excel()">导出为Excel</button> </div> <table class="table table-hover" id="mytable"> <thead> <tr> <th>驻点村居</th> <th>投稿数(总)</th> <th>投稿数(待审核)</th> <th>投稿数(审核通过)</th> <th>投稿数(审核不通过)</th> </tr> </thead> <tbody> <tr> <td>某镇某村/社区</td> <td>888</td> <td>8</td> <td>800</td> <td>80</td> </tr> <tr> <td>某镇某村/社区</td> <td>888</td> <td>8</td> <td>800</td> <td>80</td> </tr> <tr> <td>某镇某村/社区</td> <td>888</td> <td>8</td> <td>800</td> <td>80</td> </tr> </tbody> </table> </div> </div> <!--jquery一定要在前面被加载--> <script src="resource/js/lib/jquery-1.11.1.min.js"></script> <script src="resource/js/lib/FileSaver.min.js"></script> <script src="resource/js/lib/tableExport.min.js"></script> <script> function export2excel () { $('#mytable').tableExport({type:'excel'}); } </script>