didikee - 博客园

第一章 JSON语法用法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>html()/text()/val()</title>
</head>
<body>
<h1>html()设置或获取HTML代码</h1>
<div id="container">
</div>
<script src="js/jquery.js"></script>
<script>
    //JSON语法
    let list = [
        {"id":1000,"name":"祖武","gender":true,"hobby":["旅游","撩妹","美食"],"score":99.5},
        {"id":1001,"name":"周琪","gender":true,"hobby":["旅游","撩妹","美食","编程"],"score":88.5},
        {"id":1002,"name":"李小丽","gender":false,"hobby":["追剧","工作","跳舞"],"score":77.5},
        {"id":1003,"name":"李逵","gender":true,"hobby":null,"score":66.5}
    ];
    let table = `<table border="1" width="70%">
                                <tr>
                                        <th>学号</th>
                                        <th>姓名</th>
                                        <th>性别</th>
                                        <th>爱好</th>
                                        <th>成绩</th>
                                </tr>`;
    for(let stu of list){
        table +=`
                    <tr align="center" valign="middle">
                           <td>${stu.id}</td>
                           <td>${stu.name}</td>
                           <td>${stu.gender?"男":"女"}</td>
                           <td>${stu.hobby}</td>
                           <td>${stu.score}</td>
                    </tr>
               `;
    }
    table += `</table>`;
    
    $("#container").html(table);
    console.log($("#container").html());

</script>
</body>
</html>

 

posted @ 2019-07-09 20:25  排雷兵  阅读(162)  评论(0)    收藏  举报
//粒子吸附特效
  
*
*
*
*
*
*
*
*
*
*
*
*
*