javascript 使用 TableExport.js 将 HTML 表格导出为 PDF、WORD、PNG

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28789788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 09:33:34  来源:igfitidea点击:

Export HTML table to PDF, WORD, PNG using TableExport.js

javascriptjqueryhtmlpdfhtml2pdf

提问by Aman Taneja

I am trying to export a Table via PDF using the js provided by Ngiriraj Table Export Demo.The code is:

我正在尝试使用Ngiriraj Table Export Demo提供的 js 通过 PDF导出表格。代码是:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
    <script type="text/javascript" src="./js/tableExport.js"></script>
    <script type="text/javascript" src="js/jquery.base64.js"></script>
    <script type="text/javascript" src="js/sprintf.js"></script>
    <script type="text/javascript" src="js/jspdf.js"></script>
    <script type="text/javascript" src="js/base64.js"></script>
    <script src="js/jquery-1.10.2.min.js"></script>
    <script src="js/jquery.mobile-1.4.2.min.js"></script>

<title>Insert title here</title>
</head>
<body>


<button id="export" style="height: auto; width: auto;" onClick="$('#tableID').tableExport({type:'pdf',escape:'false'});">Click Here for PDF!</button>


<table id="tableID">
<tr>
<td>ABC</td>
<td>BDE</td>
</tr>
</table>
</body>
</html>

However, when I click on the button, nothing happens. Console shows a error UNCAUGHT TYPE ERRORwhenever the button is clicked.

但是,当我单击按钮时,没有任何反应。每当单击按钮时,控制台都会显示错误UNCAUGHT TYPE ERROR

回答by Jonathan

Include any scripts reliant on jQuery after the jQuery. I'd say best practice is to put jQuery first. Let me know if this works:

在 jQuery 之后包含任何依赖于 jQuery 的脚本。我会说最佳实践是将 jQuery 放在首位。让我知道这个是否奏效:

<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.mobile-1.4.2.min.js"></script>
<script type="text/javascript" src="./js/tableExport.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/sprintf.js"></script>
<script type="text/javascript" src="js/jspdf.js"></script>
<script type="text/javascript" src="js/base64.js"></script>