简体   繁体   English

将用户选择的CSV文件中的数据导入HTML文本输入

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

相关问题 MeteorJS:将数据从用户选择的json文件导入到MongoDb - MeteorJS: Import data to MongoDb from an json file selected by the user 从 html 表单中获取用户输入并将其写入文本、csv 或其他数据库文件(express.js、node.js、html) - Get user input from html form and write it to text, csv or other database file (express.js, node.js, html) 如何将 CSV 文件中的数据作为文本读取并打印到 HTML 文件中 - How To Read and Print Data from CSV file into HTML File as Text 从用户选择的文本返回 HTML - Return HTML from a user-selected text 如何将用户在FORM中选择的数据保存到.txt文件或csv文件中 - How to save the data selected by user in FORM to the .txt file or csv file 从输入类型文件选择的CSV文件生成数组 - Generate array from CSV file selected by input type file 如何将json文件中的选定数据行绑定到输入字段(文本)? - How can I bind a selected data row from a json file to an input field(text)? 将所选下拉菜单项中的文本应用于输入字段(html,javascript) - Apply text from selected dropdownmenu item to input field (html,javascript) 如何从HTML文件中的.csv输出数据? - How to output data from a .csv in an HTML file? 从HTML输入的数据生成CSV文件 - CSV file generation from HTML inputted data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM