jQuery中将json数据显示到页面表格的方法
jQuery中将json数据显示到页面表格代码。stu模拟的就是一个数据库,假设我们的数据已经是json 的文件格式,接下来就是将这个json文件里面的数据显示到页面的表格上。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script src="js/jquery-1.8.3.js"></script> <script type="text/javascript"> var stu = [ { "name": "张三", "sex": "男", "age": "20" }, { "name": "李四", "sex": "男", "age": "18" }, { "name": "王五", "sex": "男", "age": "19" } ]; $(document).ready(function() { var s = ""; for(var i = 0; i < stu.length; i++) { s = "<tr><td>" + stu[i].name + "</td><td>" + stu[i].sex + "</td><td>" + stu[i].age + "</td></tr>"; $("#tab").append(s); } }); </script> </head> <body> <table border="1px" id="tab"> <tr> <td>姓名</td> <td>性别</td> <td>年龄</td> </tr> </table> </body> </html>
相关推荐
momode 2020-09-11
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17