<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> #textareademo{ width: 600px; height: 400px; } </style> </head> <body> <textarea name="" id="textareademo" cols="30" rows="10"></textarea> <button id="funddd">fun</button> <script> window.onload = function(){ let textareademo = document.getElementById("textareademo"); let funddd = document.getElementById("funddd"); funddd.onclick = function(){ let textareaval = textareademo.value;//获取到的输入框的内容 let arrays_list = textareaval.split("\n");//通过换行符 切割每一行 获得数据 let keyarr = []; if(arrays_list.length){ let arr_obj_list = [];//数组对象 for(let i=0;i<arrays_list.length;i++){//循环每一行 let listitems = arrays_list[i];//当前循环的那一行的内容 let twoarrays = listitems.split(" ");//每个value的值 let itemrowliness = {}; let num = 0; for(let j=0;j<=twoarrays.length;j++){ let rowitemline = twoarrays[j];//这一行的每个字节 if(rowitemline!="" && rowitemline){ if(i==0){ itemrowliness[rowitemline] = "" keyarr.push(rowitemline); }else{ itemrowliness[keyarr[num]] = rowitemline; num++; } } } arr_obj_list.push(itemrowliness); } console.info("最后得到的数据:",arr_obj_list); } } } </script> </body> </html>
商品编码 数量 单位 单价
6940553360012 1 件 49.5
6902538004045 1 件 52.02
6902538005141 1 件 52.97
6902538004052 1 件 52.97
6922456805012 1 件 31
6922456889463 1 件 32.47
6922456896508 2 件 35.84
6922456892067 2 件 36.43
6922456889371 2 件 36.43
6954767433073 1 件 40
6954767413877 1 件 39.5
6954767410388 1 件 39.6
6957735788861 2 件 90
6901347880390 1 件 134
6954767434971 1 件 36
标签:function,textareademo,表格,list,js,funddd,let,文本,document From: https://www.cnblogs.com/shaozhu520/p/16999182.html