The javascript function for converting <table> table data to Json format is as follows Copy code The code is as follows:<script> var keysArr = new Array("key0", "key1", "key2"); function TableToJson(tableid) { //tableid is the name of the table you want to convert, a string, such as "example" var rows = document.getElementById(tableid).rows.length; //Get the number of rows (including thead) var colums = document.getElementById(tableid).rows[0].cells.length; //Get the number of columns var json = "["; var tdValue; for (var i = 1; i < rows; i++) { //each row json += "{"; for (var j = 0; j < colums; j++) { tdName = keysArr[j]; //Key of Json data json += "\""; //Add a double quote json += tdName; json += "\""; json += ":"; tdValue = document.getElementById(tableid).rows[i].cells[j].innerHTML; //The value of the Json data if (j === 1) {//The first column is in date format and needs to be added as follows according to JSON requirements tdValue = "\/Date(" + tdValue + ")\/"; } json += "\""; json += tdValue; json += "\""; json += ","; } json = json.substring(0, json.length - 1); json += "}"; json += ","; } json = json.substring(0, json.length - 1); json += "]"; return json; } </script> |
<<: Vue network request scheme native network request and js network request library
>>: Recommended tips for web front-end engineers
Table of contents 1. Index 1.1 Concept 1.2 Functi...
Purpose: Treat Station A as the secondary directo...
Table of contents Preface The relationship betwee...
filter is generally used to filter certain values...
This article uses examples to explain the princip...
1. Update the yum source The PostgreSQL version o...
symptom I set a crontab task on a centos7 host, b...
In the previous article https://www.jb51.net/arti...
Includes the process of initializing the root use...
The installation tutorial of mysql 8.0.11 winx64 ...
FFMPEG 3.4.1 version parameter details Usage: ffm...
Brief description Suitable for readers: Mobile de...
This article records the installation and configu...
After many difficult single-step debugging late a...
Why should we use CSS animation to replace JS ani...