嗨,我想将HTMl表下载到我的电脑上 我设法使用网上找到的示例代码来做到这一点 但是,这会下载显示的所有表格 如何指定要下载的表
function exportTableToCSV(filename) {
var csv = [];
var rows = document.querySelectorAll("table tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);
csv.push(row.join(","));
}
// Download CSV file
downloadCSV(csv.join("\n"), filename);
}
答案 0 :(得分:0)
function exportTableToCSV(tableNumber, filename) {
var csv = [];
var tables = document.querySelectorAll("table");
var rows = tables[tableNumber].querySelectorAll("tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++)
row.push(cols[j].innerText);
csv.push(row.join(","));
}
// Download CSV file
downloadCSV(csv.join("\n"), filename);
}
}
现在您可以输入要下载的表号