Insert Object data in HTML

This question already has an answer here:

  • How to loop through a plain JavaScript object with the objects as members? 17 answers

  • Just got to loop, create the HTML string, and append! Say you have a container:

    <div id="container"></div>
    

    And your JS

    var htmlString = "";
    for (var key in lists) {
        htmlString += "<span>" + key + "</span>";
        htmlString += "<ul>";
        for (var item in lists[key]) {
            htmlString += "<li>" + item + " = " + lists[key][item] + "</li>";
        }
        htmlString += "</ul>";
    }
    
    document.getElementById("container").innerHTML = htmlString;
    

    Working demo: http://jsfiddle.net/owqt5obp/

    链接地址: http://www.djcxy.com/p/52010.html

    上一篇: 循环JSON对象JavaScript

    下一篇: 在HTML中插入对象数据