zoukankan      html  css  js  c++  java
  • 用jquery把一个List里面的对象的属性,依次填入到一个table里面啊

    假设list格式如下list = [{"id":"1","name":"A","age":20}, {"id":"2","name":"B","age":21},{"id":"3","name":"C","age":22}];

    最简单的就 是  

    for(var index = 0,l = list.length;index<l;index++)

    {   $("#students tbody").append("<tr><td>"+ list[index].id +"</td><td>"+ list[index].name+"< /td><td>"+ list[index].age +"</td>< /tr>");  }

    students 是table的id

    <!DOCTYPE html PUBLIC "-//W3C //DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD /xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999 /xhtml"><head>

    <meta http-equiv="Content-Type" content="text /html; charset=gb2312" />

    <title>无标题文档</title>

    </head>

    <script language="javascript" src="/js/jquery-1.4.4.js" type="text /javascript">< /script>

    <script language="javascript" type="text/javascript">

    $(document).ready(function () { 

     var list = [{"id":"1","name":"A","age":20}, {"id":"2","name":"B","age":21}, {"id":"3","name":"C","age":22}]; 

     for(var index = 0,l = list.length; index<l;index++) { 

      $("#students tbody").append("<tr><td>"+ list[index].id +"</td><td>"+ list[index].name+"< /td><td>"+ list[index].age +"</td>< /tr>");

      } })

    </script>

    <body>

    <table id="students">

      <thead>      <tr>       <th>学 号</th>        <th>姓名</th>        <th>年龄< /th>      </tr>    </thead>   

    <tbody>   

    </tbody>

    </table>

    </body>

  • 相关阅读:
    [JOISC2017]細長い屋敷
    Gym102471C Dirichlet k-th root
    CF1264F Beautiful Fibonacci Problem
    Luogu P4619 [SDOI2018]旧试题
    AGC001F Wide Swap
    BZOJ4289 [PA2012]Tax
    Luogu P4366 [Code+#4]最短路
    Luogu P1407 [国家集训队]稳定婚姻
    CF1023F Mobile Phone Network
    BZOJ3563 DZY Loves Chinese
  • 原文地址:https://www.cnblogs.com/donchen/p/4598421.html
Copyright © 2011-2022 走看看