The format of the table is more general, the first behavior field, the following behavior data, the table ID is detaillist.
$ ("#submitExcel"). Click (function () { //Bind order Click event insertstr= "INSERT into funddetail values";//Insert string initial value $ ("# Detaillist tr:gt (0) "). each (function (i) { //Gets the table all rows except the first row and adds a method to each row insertstr+=" (null, "; Continue to increase the insert string $ (this). Find (' TD '). each (function (j) {///gets all the columns contained in the current row and adds a method to each column (that is, each cell), I is the ordinal number on the column if (j==7)// Because the 7th column in each row is a form control, the value {insertstr+=$ (this) is obtained in a different way. Find (' select '). val () + ","; Continue to increase the insert string}else{insertstr+= "'" +$ (This). Text () + "',"//continue to increment the insert string, note the last comma}) insertstr= Insertstr.substring (0,insertstr.length-1); Delete each line last comma insertstr+= "),"; Sets the end of the INSERT statement for the current line, plus a comma to facilitate the next row of data}) insertstr=insertstr.substring (0,insertstr.length-1); Delete the last comma of the final insert string//The resulting insert string is passed to the background page for processing $.ajax ({type: "Post", Data:{insertstring:insertstr}, in Ajax mode). DataType: ' html ', url: ' phpcode/saveexcel.php ', success:function (data) {alert (data);});});
JQuery reads the data from the page table to generate bulk insert code and pass it to the background in AJAX mode