• 66作业


    """
    2、现有以下成绩单数据
    scores = [
    	{ name: 'Bob', math: 97, chinese: 89, english: 67 },
    	{ name: 'Tom', math: 67, chinese: 52, english: 98 },
    	{ name: 'Jerry', math: 72, chinese: 87, english: 89 },
    	{ name: 'Ben', math: 92, chinese: 87, english: 59 },
    	{ name: 'Chan', math: 47, chinese: 85, english: 92 },
    ]
    用table表格标签渲染以上数据,表格第一列是学生总分排名,最后一列是学生总分;
    """"
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
        <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
        <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    
    </head>
    
    <body>
        <div class="container">
            <div class="row">
                <div class="col-md-8 col-md-offset-2">
                    <table class="table table-hover table-bordered table-striped" id="table">
                        <thead>
                            <tr>
                                <!-- <th>序号</th> -->
                                <th>排名</th>
                                <th>姓名</th>
                                <th>语文</th>
                                <th>数学</th>
                                <th>英语</th>
                                <th>总分</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for='(stu,i) in scores'>
                                <!-- 怎么取到值去相加求和 -->
                                <!-- <td>{{ i }}</td> -->
                                <td>{{ i+1 }}</td>
                                <td v-for='v in stu'>{{ v }}</td>
    
                            </tr>
                        </tbody>
    
                    </table>
                </div>
            </div>
        </div>
    
    </body>
    <script src="js/vue.js"></script>
    <script>
        let scores = [{
                name: 'Bob',
                math: 97,
                chinese: 89,
                english: 67
            },
            {
                name: 'Tom',
                math: 67,
                chinese: 52,
                english: 98
            },
            {
                name: 'Jerry',
                math: 72,
                chinese: 87,
                english: 89
            },
            {
                name: 'Ben',
                math: 92,
                chinese: 87,
                english: 59
            },
            {
                name: 'Chan',
                math: 47,
                chinese: 85,
                english: 92
            },
    
        ];
    
        let total_scores = [];
        for (stu of scores) {
            stu.sum = stu.math + stu.chinese + stu.english;
            total_scores.push(stu);
        }
       
    
    
        for(let i = 0; i < total_scores.length - 1; i++) {
            for(let j = 0;  j < total_scores.length - 1 - i; j++) {
                if (total_scores[j].sum < total_scores[j+1].sum) {
                    let t = total_scores[j];
                    total_scores[j] = total_scores[j+1];
                    total_scores[j+1] = t;
                }
            }
        }
        console.log(total_scores)
    
        new Vue({
                    el: '#table',
                    data: {
                        scores: total_scores,
                    }
                   
        })
    </script>
    
    </html>
    """
    3、还是采用上方相同的数据,采用相同的渲染规则,只渲染所有科目都及格了的学生。
    """
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
        <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
        <script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
    
    </head>
    
    <body>
        <div class="container">
            <div class="row">
                <div class="col-md-8 col-md-offset-2">
                    <table class="table table-hover table-bordered table-striped" id="table">
                        <thead>
                            <tr>
                                <!-- <th>序号</th> -->
                                <th>排名</th>
                                <th>姓名</th>
                                <th>语文</th>
                                <th>数学</th>
                                <th>英语</th>
                                <th>总分</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr v-for='(stu,i) in scores' v-if="stu.math>60&&stu.chinese>60&&stu.english>60">
                                <td>{{ i+1 }}</td>
                         
                                <td v-for='v in stu'>{{ v }}</td>
    
                            </tr>
                        </tbody>
    
                    </table>
                </div>
            </div>
        </div>
    
    </body>
    <script src="js/vue.js"></script>
    <script>
        let scores = [{
                name: 'Bob',
                math: 97,
                chinese: 89,
                english: 67
            },
            {
                name: 'Tom',
                math: 67,
                chinese: 52,
                english: 98
            },
            {
                name: 'Jerry',
                math: 72,
                chinese: 87,
                english: 89
            },
            {
                name: 'Ben',
                math: 92,
                chinese: 87,
                english: 59
            },
            {
                name: 'Chan',
                math: 47,
                chinese: 85,
                english: 92
            },
    
        ];
    
        let total_scores = [];
        for (stu of scores) {
            stu.sum = stu.math + stu.chinese + stu.english;
            total_scores.push(stu);
        }
       
    
    
        for(let i = 0; i < total_scores.length - 1; i++) {
            for(let j = 0;  j < total_scores.length - 1 - i; j++) {
                if (total_scores[j].sum < total_scores[j+1].sum) {
                    let t = total_scores[j];
                    total_scores[j] = total_scores[j+1];
                    total_scores[j+1] = t;
                }
            }
        }
        console.log(total_scores)
    
        new Vue({
                    el: '#table',
                    data: {
                        scores: total_scores,
                    }
        });
    </script>
    
    </html>
    
  • 相关阅读:
    js鼠标右键菜单
    js变量作用域好玩的东东
    清除浮动
    http通信示例Httpclient和HttpServer
    sql复杂案例
    微信小程序(小游戏)后台开发
    自动授时同步NTP时钟之NTP农历源代码算法立显电子技术部宣
    NTP同步时钟系统的实现及局域网授时方法
    modbus协议显示屏|modbus通讯显示屏|modbus显示电子屏功能码实现代码分享
    带掉电记忆功能的LED时钟代码分享
  • 原文地址:https://www.cnblogs.com/lyyblog0715/p/12057395.html
Copyright © 2020-2023  润新知