时间:2021-07-01 10:21:17 帮助过:7人阅读
话不多说其实就是一个简单的js 的for循环
js代码:
$(function(){ var str=[{name:"zy",age:111,sex:0,pass:1},{name:"zay",age:112},{name:"zby",age:113},{name:"zcy",age:114}]; obj=eval(str); var ht = ''; for(var i=0;i<obj.length;i++){/ ht = ht+'<tr>'; ht = ht + '<td>' + obj[i].name + '</td>'; ht = ht + '<td>' + obj[i].age + '</td>'; ht = ht + '<td>' + obj[i].sex + '</td>'; ht = ht + '<td>' + obj[i].pass + '</td>'; ht = ht+'</tr>'; } $('#tb').append(ht); })
html代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>表格</title> <link rel="stylesheet" href="css/table.css" /> <script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/table.js"></script> </head> <body> <p> <table id="tb" > <tr> <td>1</td> <td>1</td> <td>1</td> </tr> </table> </p> </body> </html>
以上就是如何把 json输出至table 的详细内容,更多请关注Gxl网其它相关文章!