The goal is to assign multiple values to a table on the page.
1) First version of the code
<table border= "1" id= "Divdata" > <tr> <th class= "bglist-2" > JO & lt;/th> <th class= "bglist-2" > Information </th> <th class= "Bglist-2" ; Scan time </th> <th class= "bglist-2" > Scan mega </th> </tr> </table> for (i = 0; i < json.length; i++) {strtemp = strtemp + "<tr ><TD class= ' bglist-1 ' > ' + json[i]. JoNo + "</td><td class= ' bglist-1 ' >" + json[i]. Info + "</td><td class= ' bglist-1 ' >" + json[i]. Createtime + "</td><td class= ' bglist-1 ' >" + json[i]. creater + "</td></tr>"; } var x = document.getElementById ("Divdata"); for (i = x.childnodes.length-1; i > 1; i--) {x.removechild (x.childnodes[i])} x.innerhtml = X.innErhtml + strtemp;
In IE10 and chrome under test ok,user use IE8, direct JS error, dizzy to.
Check the information, found that some people said innerHTML in IE8 there are some problems
2) Second Edition code
<table border= "1" > <tr> <th class= "Bglist-2" &G T JO </th> <th class= "bglist-2" > Information </th> <th class = "Bglist-2" > Scan time </th> <th class= "bglist-2" > Scan Mega </th> </tr> <div id= "Divdata" ></div> </table> for ( i = 0; i < json.length; i++) {strtemp = strtemp + "<tr><td class= ' bglist-1 ' >" + json[i]. JoNo + "</td><td class= ' bglist-1 ' >" + json[i]. Info + "</td><td class= ' bglist-1 ' >" + json[i]. Createtime + "</td><td class= ' bglist-1 ' >" + json[i]. creater + "</td></tr>"; } var x = document.getElementById ("Divdata"); x.innerhtml = x.innerhtml + strtemp;
Now do not error, but the page is garbled, Div will be placed in front of the table, and there is no lattice.
3) Third edition code
<div id= "Divdata" > </div> var strtemp = "<table border= ' 1 ' ><tr><th class= ' Bglist-2 ' >jo</th><th class= ' bglist-2 ' > Info </th><th class= ' bglist-2 ' > Scan time "; strtemp = strtemp + "</th><th class= ' bglist-2 ' > Scan Mega </th></tr>"; for (var i = 0; i < json.length; i++) { strtemp = strtemp + "</tr><tr><td class= ' bglist-1 ' >" + Json[i]. JoNo + "</td><td class= ' bglist-1 ' >" + json[i]. Info + "</td><td class= ' bglist-1 ' >" + New Date (parseint (json[i). Createtime.replace ("/date (", ""). Replace (")/", ""), ()). toLocaleString () + "</td><td class= ' bglist-1 ' > "+ json[i]. creater + "</td></tr><tr>"; } var x = document.getElementById ("Divdata"); x.innerhtml = strtemp+ "</table>";
The whole world is quiet, everyone is in the same, meet the requirements
The final version is modified to the jquery version to ensure maximum compatibility.
$ ("#divData"). HTML (strtemp + "</table>");
innerHTML's Problem