innerHTML's Problem

Source: Internet
Author: User

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 &GT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.