Insert Object data in HTML
This question already has an answer here:
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中插入对象数据