我想将我的 html 表导出到 CSV 文件。有没有简单的代码?用户将使用两个或三个步骤并下载 CSV。
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
</tr>
</thead>
<tr>
<td rowspan='2'>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
</tr>
<tfoot>
<tr>
<th colspan='2'>6 <span style='display:none'> 7
</span> 8</th>
</tr>
</tfoot>
</table>
Run Code Online (Sandbox Code Playgroud)
tabletoCSV 是一个极简的 jQuery 工具,用于将 html 表转换/导出为 CSV(逗号分隔值)文件。只需使用这三个简单的步骤,CSV 就会导出。
1. Include jQuery library and the jQuery tabletoCSV plugin on the web page.
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://www.jqueryscript.net/demo/jQuery-Plugin-To-Convert-HTML-Table-To-CSV-tabletoCSV/jquery.tabletoCSV.js"></script>
2. Add a button for table to CSV export.
<button id="export" data-export="export">Export</button>
3. Enable the Table To CSV tool.
$("#export").click(function(){
$("table").tableToCSV();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6376 次 |
| 最近记录: |