js对象for生成页面

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />       
        <title>挑战题</title>
        <style>
            .ui-table {margin: 20px auto; border-collapse: collapse; font-size: 12px; text-align: center; color: #666;}
            .ui-table th, .ui-table td {padding: 4px 8px; border: 1px solid #ccc;}
            .ui-table th {background-color: #f0f0f0;}
        </style>
        <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
    </head>
    <body>
        <table class="ui-table" width="800" id="studentInfo">
            <caption><h2>js对象for生成页面</h2></caption>
            <thead>
            <tr>
                <th style="width:45px">序号</th>
                <th>姓名</th>
                <th>学号</th>
                <th>性别</th>
                <th>年龄</th>
                <th>所在班级</th>
                <th>富二代</th>
            </tr>
            </thead>
            <tbody>
                <tr>
                    <td colspan="7">
                        <input type="button" value="加载资料" οnclick="DisplayInfo()">
                    </td>
                </tr>
            </tbody>
        </table>
        <script>
        var students = [
            {"name": "张三", "id": "00145", "sex": "男", "age": "15", "class": "初一(3)班", "vip": "否"},
            {"name": "李四", "id": "00110", "sex": "女", "age": "15", "class": "初二(2)班", "vip": "否"},
            {"name": "王五", "id": "00251", "sex": "男", "age": "17", "class": "初一(4)班", "vip": "是"},
            {"name": "赵六", "id": "00031", "sex": "女", "age": "16", "class": "初二(3)班", "vip": "否"},
            {"name": "吴七", "id": "00009", "sex": "女", "age": "19", "class": "初三(6)班", "vip": "否"},
            {"name": "候八", "id": "00352", "sex": "男", "age": "14", "class": "初一(2)班", "vip": "是"},
        ];     
        function DisplayInfo() {
            var tbody = $("#studentInfo").find("tbody");
                tbody.empty();
            $.each(students,function(index, el) {
                tbody.append(
                    "<tr><td>" + parseInt(index+1) + "</td><td>" +
                                  el.name + "</td><td>" +
                                  el.id +   "</td><td>" +
                                  el.sex +   "</td><td>" +
                                  el.age +   "</td><td>" +
                                  el.class +   "</td><td>" +
                                  el.vip +   "</td></tr>");
            });
        }
        </script>
    </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值