我試圖將表格內容導出並保存爲CSV,並且其工作正常,但我想在導出保存之前隱藏/刪除特定的div。 我想要隱藏/刪除span.delete-list-domains,然後導出/將我的表格保存爲CSV。將表導出爲CSV
jQuery(document).ready(function ($) {
function exportTableToCSV($table, filename) {
//$("span.delete-list-domains").hide();
var $rows = $table.find('tr:has(td)'),
tmpColDelim = String.fromCharCode(11),
tmpRowDelim = String.fromCharCode(0),
colDelim = '","',
rowDelim = '"\r\n"',
csv = '"' + $rows.map(function (i, row) {
var $row = $(row),
$cols = $row.find('td');
return $cols.map(function (j, col) {
var $col = $(col),
text = $col.text();
return text.replace(/"/g, '""');
}).get().join(tmpColDelim);
}).get().join(tmpRowDelim)
.split(tmpRowDelim).join(rowDelim)
.split(tmpColDelim).join(colDelim) + '"';
// Deliberate 'false', see comment below
if (false && window.navigator.msSaveBlob) {
var blob = new Blob([decodeURIComponent(csv)], {
type: 'text/csv;charset=utf8'
});
window.navigator.msSaveBlob(blob, filename);
} else if (window.Blob && window.URL) {
var blob = new Blob([csv], { type: 'text/csv;charset=utf8' });
var csvUrl = URL.createObjectURL(blob);
$(this)
.attr({
'download': filename,
'href': csvUrl
});
} else {
var csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv);
$(this)
.attr({
'download': filename,
'href': csvData,
'target': '_blank'
});
}
}
$(".export").on('click', function (event) {
var args = [$('#dvData>table'), 'export.csv'];
exportTableToCSV.apply(this, args);
});});
錯誤在哪裏?你評論過將會隱藏div的行。 –
嗨!此行不起作用$(「span.delete-list-domains」)。hide(); – Tony
是出口工作嗎? 你確定這個跨度的類名嗎? try $(「。delete-list-domains」)。hide(); 嘗試在jQuery(document).ready之前聲明該函數,然後在那裏調用它 –