Suppose the list format is as follows list = [{"id": "1", "name": "A", "Age":--}, {"id": "2", "Name": "B", "Age": 21},{"id": "3", "Name": "C", "Age": 22}
The simplest is
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 is the ID of the table
<! DOCTYPE HTML PUBLIC "-//w3c//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<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":-}, {"id": "2", "Name": "B", "Age": +}, {"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> Study number </th> <th> name </th> <th> Age </th> ; </tr> </thead>
<tbody>
</tbody>
</table>
</body>
Use jquery to put the properties of an object in a list into a table.