<html><head><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script><script> $(function() { var people = []; $.getJSON('people.json', function(data) { $.each(data.person, function(i, f) { var tblRow = "<tr>" + "<td>" + f.firstName + "</td>" +"<td>" + f.lastName + "</td>" + "<td>" + f.job + "</td>" + "<td>" + f.roll + "</td>" + "</tr>"$(tblRow).appendTo("#userdata tbody"); }); });});</script></head><body><div ><div > <table id= "userdata" border="2"> <thead> <th>First Name</th> <th>Last Name</th> <th>Email Address</th> <th>City</th> </thead> <tbody> </tbody> </table></div></div></body></html>
我的
JSON档案:
{ "person": [ {"firstName": "Clark","lastName": "Kent","job": "Reporter","roll": 20 }, {"firstName": "Bruce","lastName": "Wayne","job": "Playboy","roll": 30 }, {"firstName": "Peter","lastName": "Parker","job": "Photographer","roll": 40 } ]}
经过一天的工作,我成功地将
JSON文件集成到
HTML表中!!!!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)