模拟读取CSV数据文件,查找标题行和数据行
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> </head> <body> <script> var lineData=new Array( "", "a1,22,33,44,55,66,77,88,99,00,11,22", "a2,22,33,44,55,66,77,88,99,00,11,22,33", "", "", "a3,22,33,44,55,66,77,88,99,00,11,22", "a4,22,33,44,55,66,77,88,99,00,11,22", "a5,22,33,44,55,66,77,88,99,00,11,22,33", "a6,22,33,44,55,66,77,88,99,00,11,22,33"); function getHeadLine(lineData){ var retHeadLine = 0; for (i = 0; i < lineData.length -1 ; i++) { if ( lineData[i] == "" ) { continue; } var objLines = lineData[i].split(","); if ( objLines.length == 13 ) { retHeadLine = i; break; } } alert(retHeadLine); return retHeadLine; } function getDataLine(lineData,iStart){ var retHeadLine = 0; for (i = iStart; i < lineData.length -1 ; i++) { if ( lineData[i] == "" ) { continue; } var objLines = lineData[i].split(","); if ( objLines.length == 13 ) { retHeadLine = i; break; } } alert(retHeadLine); return retHeadLine; } </script> <form method="post" action=""> <input type="button" value="getHeadLine" onclick="return getDataLine(lineData,0);"> <input type="button" value="getDataLine" onclick="return getDataLine(lineData,(2+1));"> </form> </body> </html>