首页 > 其他 > 详细

项目实战

时间:2016-05-02 21:12:38      阅读:116      评论:0      收藏:0      [点我收藏+]

html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
        <style type="text/css">
            table{border-collapse: collapse; width: 100%;}
            table tr td{border: red solid 1px;  width: 50%; text-align: center;}
        </style>
    </head>
    <body>
        <table>
        </table>
        <script type="text/javascript">
            $.ajax({   
                type: "get",   
                  url:  "DB.json", 
                  datatype: "json",
                   success: function (data) {
                       for (var i=0; i<data.length; i++) {
                           $("table").append(
                               "<tr><td>"+data[i].name+"</td><td>"+data[i].age+"</td></tr>"
                           )
                       }
                   },
                   error:function () { alert("Ajax请求Json错误");}
               });
        </script>
    </body>
</html>

 

json

[
{"name": "小王",  "age": "10" },
{ "name": "小丁",  "age": "20" },
{ "name": "小红",  "age": "18" }
]

 

效果

技术分享

项目实战

原文:http://www.cnblogs.com/flyings/p/5453092.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!