我想将用户选择的CSV文件中的联系号码导入HTML文本输入字段。我的CSV文件存储名称和手机号码,我想将所有手机号码导入以空格或,
分隔的HTML文本输入
您可以使用Papa Parse从CSV文件中读取数据。这是正在运行的例子。
var mob = [];
$("input[type=file]").change(function(){
$("input[type=file]").parse({
config: {
delimiter: "", // auto-detect
newline: "", // auto-detect
quoteChar: '"',
header: false,
complete: function(results, file) {
for(var i=0; i<results.data.length;i++){
mob.push(results.data[i][1]); //modify this line as per the format of your CSV file
}
console.log(mob);
$(".d").val(mob.toString());
}
}
});
});
<!DOCTYPE html>
<html>
<head>
<title>Papa</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.3.7/papaparse.min.js"></script>
</head>
<body>
<input type="file">
<input type="text" class="d">
</body>
</html>
我的CSV文件以以下格式存储数据name,mobile
,因此数组中移动号码的位置将为[1]