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
I am writing a small program recently. Because th...
ElementUI implements a table tree list loading tu...
First, your container must be running You can vie...
With the development of Internet technology, user...
Allow './' relative paths in docker-compo...
max_allowed_packet is a parameter in MySQL that i...
Prerequisite: The web developer plugin has been in...
The value of the background property in CSS backg...
Table of contents Preface Scenario simulation Sum...
The transaction log records the operations on the...
Table of contents Preface keep-avlive hook functi...
Sometimes our pages will need some prompt boxes o...
This example takes the installation of Python 3.8...
Table property settings that work well: Copy code ...
Solution to MySql service disappearance for unkno...