HTML的

文章描述了一个HTML页面,使用Vue.js构建了一个包含动态表格(显示学生姓名、科目和成绩,以及删除功能)和数据输入表单的示例。表格根据用户输入的数据实时更新总分和平均分。
摘要由CSDN通过智能技术生成

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <style>

        .boss {

            width: 1000px;

            height: 500px;

            display: flex;

            margin: 0 auto;

        }

        .box1 {

            flex: 8;

            height: 100%;

            box-sizing: border-box;

            padding: 50px;

        }

        .box2 {

            flex: 4;

            height: 100%;

            box-sizing: border-box;

            padding: 50px 0;

            font-size: 20px;

        }

        .box2 input {

            width: 200px;

            height: 50px;

            margin-bottom: 20px;

            font-size: 16px;

        }

        button {

            width: 70px;

            height: 40px;

            margin-left: 60px;

            background-color: rgb(0,101,158);

            color: #fff;

            border-radius: 10px;

            border: none;

        }

    </style>

</head>

<body>

    <div id="app">

        <div class="boss">

            <div class="box1">

                <table width="100%" border="1" cellpadding="0" cellspacing="0" align="center">

                    <tr style="background-color: rgb(245,245,245);border: none;" height="40px">

                        <th>编号</th>

                        <th>姓名</th>

                        <th>科目</th>

                        <th>成绩</th>

                        <th>操作</th>

                    </tr>

                    <tr style="text-align: center;border: none;" height="40px" v-for="(item,index) of arr">

                        <td>{{index+1}}</td>

                        <td>{{item.userName}}</td>

                        <td>{{item.km}}</td>

                        <td v-if="item.cj>=60">{{item.cj}}</td>

                        <td style="color: red;" v-if="item.cj<60">{{item.cj}}</td>

                        <td>

                            <div style="text-decoration: underline;cursor: pointer;" @click="sc(index)">删除</div>

                        </td>

                    </tr>

                   

                </table>

                <table width="100%" border="1" cellpadding="0" cellspacing="0" align="center">

                    <tr style="text-align: center;border: none;" v-if="xs" height="40px">

                        <td style="border: none;text-align: right;">总分:</td>

                        <td style="border: none;text-align: left;padding-left: 20px;box-sizing: border-box;">{{zf}}</td>

                        <td style="border: none;text-align: right;">平均分:</td>

                        <td style="border: none;padding-left: 20px;box-sizing: border-box;text-align: left;">{{pjf}}</td>

                        <!-- <td style="border: none;"></td> -->

                    </tr>

                </table>

               

            </div>

            <div class="box2">

                姓名:<input type="text" v-model="obj.userName" placeholder="请输入姓名">

                <br>

                科目:<input type="text" v-model="obj.km" placeholder="请输入科目">

                <br>

                分数:<input type="text" v-model="obj.cj" placeholder="请输入分数">

                <br>

                <button @click="tj()">添加</button>

            </div>

        </div>

    </div>

</body>

<script src="./vue.js"></script>

<script>

    Vue.config.productionTip = false;

    var vm = new Vue({

        el:"#app",

        data(){

            return{

                arr:[],

                xs:true,

                zf:"",

                pjf:"",

                arrs:[],

                sum1:0,

                ys:{},

                obj:{

                    userName:"",

                    km:"",

                    cj:"",

                },

            }

        },

        methods:{

            tj(){

                this.arr.push(this.obj);

                this.obj.cj=Number(this.obj.cj);

                   this.sum1+=this.obj.cj;

                    console.log(this.sum1);

                    this.zf=this.sum1;

                    this.pjf=(this.sum1/this.arr.length).toFixed(1);

                this.obj={

                    userName:"",

                    km:"",

                    cj:""

                }

                if(this.pjf=="NaN"){

                    this.pjf=0;

                }

            },

            sc(a){

                console.log(this.arr[a].cj);

                this.sum1-=this.arr[a].cj;

                this.zf=this.sum1;

                this.arr.splice(a,1)

                this.pjf=(this.sum1/this.arr.length).toFixed(1);

                if(this.pjf=="NaN"){

                    this.pjf=0;

                }

            }

        }

    })

</script>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值