簡體   English   中英

將用戶選擇的CSV文件中的數據導入HTML文本輸入

[英]import data from user selected CSV file to HTML text input

我想將用戶選擇的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存儲數據name,mobile因此該移動電話號碼在數組中的位置為[1]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM