http://papaparse.com/
https://github.com/mholt/PapaParse
我用的是从本地选择csv文件上传,文件选择框id为file
if (!$('#file')[0].files.length) {
alert("请选择数据文件");
} else {
var config = {
delimiter: "",// auto-detect
newline: "",// auto-detect
header: true,
dynamicTyping: false,
preview: 0,
encoding: "UTF-8",
worker: false,
comments: false,
step: undefined,
complete: completeFn,//上传成功时执行哪个函数
error: undefined,
download: false,
skipEmptyLines: true,
chunk: undefined,
fastMode: undefined,
beforeFirstChunk: undefined
}
$('#file').parse({
config: config
});
}
function completeFn(results) {
//这里我提取了fields,可以根据实际情况提取其他内容
initDialog(results.meta.fields);
};