【发布时间】:2020-03-22 23:37:53
【问题描述】:
我正在尝试使用 Jquery 导出 div 数据。但价值来自同一个单元格
这里是示例图片:
我需要下面的示例图片:
有些东西遗漏了我的代码,请帮助我。
JS:
var csvContent= "First Name, Middle Name, Last Name"; // Headers for CSV file
var dataElements = document.getElementsByClassName("sample");
for (var i = 0; i < dataElements.length; i++) { // we iterate through all data entries
// If your ids per entry (one person) are fix (which is a bad idea)
var entryLineCsv = document.getElementById("kaf70").innerHTML + ","
+ document.getElementById("kaf71").innerHTML + ","
+document.getElementById("kaf72").innerHTML + ","; // here we got on csv line
createCsvFile(entryLineCsv);
}
function createCsvFile(addEntryLineIoCsv) {
let file = new Blob([csvContent = csvContent + addEntryLineIoCsv], { type: "application/vnd.ms-excel" });
let url = URL.createObjectURL(file);
let a = $("<a />", {
href: url,
download: "filename.xls"
}).appendTo("body").get(0).click();
}
HTML:
div class="losSection" id="secReviewerDemographics"><div class="losSectionHeader"><div class="losSectionSel losSectionTitle misign" data-originaltitle="Demographics">Demographics</div></div><div id="cpC_kf_secview_50" class="losSectionView"><div>
<div id="ExportDetails" class="sample">
<div class="tabularView">
<input type="hidden" name="kaf_78" id="kaf_78" aria-label="kaf_78" value="01" class="._shCE">
<div id="cpC_ctl73" class="tabularTbl flex-row start-xs">
<div class="pad1x flex-row leftLblMode">
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div style="">
<label for="kaf_70" id="klb_70" class="input-control-label input-control-label input-control-label input-control-label input-control-label input-control-label">First Name
</label>
</div>
</div>
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div class="labelValueField">
<span class="labelValue" name="kaf_70" id="kaf_70">
<span class="labelValue" name="kaf_70" id="kaf70" aria-label="Applicant First Name">NAMA</span>
</span>
</div>
</div>
</div>
<div class="pad1x flex-row leftLblMode">
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div style="">
<label for="kaf_71" id="klb_71" class="input-control-label input-control-label input-control-label input-control-label input-control-label input-control-label">Middle Name</label>
</div>
</div>
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div class="labelValueField">
<span class="labelValue" name="kaf_71" id="kaf_71">
<span class="labelValue" name="kaf_71" id="kaf71" aria-label="Applicant Middle Name">VEENESH</span>
</span>
</div>
</div>
</div>
<div class="pad1x flex-row leftLblMode">
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div style="">
<label for="kaf_72" id="klb_72" class="input-control-label input-control-label input-control-label input-control-label input-control-label input-control-label">Last Name
</label>
</div>
</div>
<div class="pad1x flex-col-xs-12 flex-col-sm-6">
<div class="labelValueField">
<span class="labelValue" name="kaf_72" id="kaf_72">
<span class="labelValue" name="kaf_72" id="kaf72" aria-label="Applicant Last Name">KUMAR</span>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div></div>
<button id="ExportToExcel" onclick="exportF(this)">Export To Excel</button>
演示代码:DEMO LiNK
【问题讨论】:
标签: javascript jquery html css