[英]import data from user selected CSV file to HTML text input
我想将用户选择的CSV文件中的联系人号码导入到HTML文本输入字段中。我的CSV文件存储名称和手机号码,并且要将所有手机号码导入到HTML文本输入中,并以空格或分隔,
You can use Papa Parse to read data from your CSV file. 您可以使用Papa Parse读取CSV文件中的数据。 Here's the running example. 这是正在运行的示例。
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>
My CSV file stores data in the following format name,mobile
so the position of the mobile number in the array will be [1]
我的CSV文件以以下格式name,mobile
存储数据name,mobile
因此该移动电话号码在数组中的位置为[1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.