zoukankan      html  css  js  c++  java
  • 如何循环遍历json数据到table

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6     <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.js"></script>
     7     <style type="text/css">
     8         
     9     </style>
    10 </head>
    11 <body>
    12     <table id="myTable">
    13         <thead>
    14             <tr>
    15                 <th>代号</th>
    16                 <th>城市</th>
    17                 <th>附加数字</th>
    18             </tr>
    19         </thead>
    20         <tbody></tbody>
    21     </table>
    22 </body>
    23 </html>
    24 <script type="text/javascript">
    25     var data = [{name:'6101',value:'北京市',age:'11'}, {name:'6102',value:'天津市',age:'11'}, {name:'6103',value:'上海市',age:'22'}];
    26     $.each(data,function(index,item){
    27         var $tr = $('<tr>');
    28         $.each(item,function(name,val){
    29             var $td = $('<td>').html(val);
    30             $tr.append($td);
    31         });
    32         $('#myTable tbody').append($tr);
    33     });
    34 </script>
  • 相关阅读:
    HDU-6315 Naive Operations 线段树
    18牛客第二场 J farm
    POJ
    SPOJ
    codeforces 501C. Misha and Forest
    Codeforces 584C
    Domination
    HDU-3074 Multiply game
    Codefoeces-689D Friends and Subsequences
    Codeforces Round #486 (Div. 3)
  • 原文地址:https://www.cnblogs.com/dancer0321/p/13253274.html
Copyright © 2011-2022 走看看