根據反饋,我的原始問題沒有意義。 試圖查看是否有另一種方式來讀取Papa解析的CSV。如何使用純Javascript解析CSV
我當前的代碼:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="./papaparse.min.js"></script>
<script>
var data;
// Target first (and only) file selected
function handleFileSelect(evt) {
var file = evt.target.files[0];
// Parse the file
Papa.parse(file, {
header: true,
download: true,
dynamicTyping: true,
complete: function(results) {
data = results;
console.log(data);
}
});
}
// Run handleFileSelect function when document is ready
$(document).ready(function(){
$("#testCsv").change(handleFileSelect);
});
</script>
<!--File button to upload file-->
<input type="file" id="testCsv" name="files"/>
編輯:顯然,我需要根據向下票做一些更多的研究。對不起,這個東西是全新的。我的一次新的嘗試:
var data;
function parseCSV(file) {
Papa.parse(file, {
header: true,
download: true,
dynamicTyping: true,
complete: function(results) {
data = results;
console.log(results); // results appear in dev console
}
});
}
parseCSV(document.getElementById("testCSV").files[0]);
返回一個錯誤:
ReferenceError: document is not defined
做更多的研究。
我在該代碼中看到您使用jQuery的唯一部分是將更改處理程序附加到元素的位置。因此,研究如何在「純」JS中添加事件處理程序。 – CBroe
*「... with pure Javascript」*關於使用jQuery或沒有與JavaScript的「純度」有關的任何內容都沒有。如果你想在沒有任何庫的情況下做到這一點,你要問的是如何用DOM API來做到這一點。 jQuery和DOM API版本都是「純粹的」JavaScript。 –
好吧,顯然我對JQuery一無所知,需要做更多的研究。對於web開發人員來說,還是很新的,謝謝你的迴應。 – FF5Ninja