简体   繁体   中英

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. 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM