Javascript 动态把JSON转成表格显示

Javascript 动态把JSON转成表格显示

<html>
    <body>
            <table id="table1">
            </table>
    </body>
<script src="http://www.oschina.net/js/2012/jquery-1.7.1.min.js?t=1451961936000"></script>
<script>
  var data = [{name: "Andy",Age:18,Blogs:"OSC"},{name: "Lily",Age:21,Blogs:"OSC111"},{name: "Bou",Age:32,Blogs:"OSCsss"},];
            var html;
            $.each(data, function (index, item) {
                if (index === 0) {
                    html += "<tr>";
                    $.each(item, function (vlaIndex) {
                        html += "<td>";
                        html += vlaIndex;
                        html += "</td>";
                    });
                    html += "</tr>";
                }
                html += "<tr>";
                $.each(item, function (vlaIndex, valItem) {
                    html += "<td>";
                    html += valItem;
                    html += "</td>";
                });
                html += "</tr>";
            });
 $("#table1").html(html);

</script>

</html>

posted @ 2016-08-18 14:20  游子善心  阅读(0)  评论(0编辑  收藏  举报  来源