首页 > 其他分享 >随机点名、、、添加学生

随机点名、、、添加学生

时间:2022-09-30 17:45:18浏览次数:40  
标签:点名 name classList list value add 添加 随机 display



    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
    <title>Document</title>
//vue应用

 

 1 <body>
 2     <div id="App">
 3         <div style="display: flex;justify-content: center">
 4             老师:<span>{{add}}</span>
 5         </div>
 6         <input type="text" v-model="name" > <button @click="adds()" > 添加班级成员 </button>
 7         <div class="name-box">
 8             <div :class="{name:true, active:list.includes(value)}" v-for="(value,index) of classList">{{value}} <div class="delete" @click="deleteName(value)" >×</div></div>
 9         </div>
10         <button @click="callTheRoll()" > 点名 </button>
11         <button @click="ToCallTheRoll()" > 重新点名 </button>
12         <br>
13         <div>{{list}}</div>
14     </div>
15 </body>
    <style>
        *{
            padding: 0px;
            margin: 0px;
        }
        .name-box{
            display: flex;
            width: 1200px;
            padding: 20px;
            border-radius: 8px;
            border: 1px solid #666;
            flex-wrap: wrap;
            margin: 0 auto;
        }
        .name{
            width: 10%;
            height: 30px;
            margin: 10px 1.25%;
            display: flex;
            justify-content: center;
            align-items: center;
            border-radius: 4px;
            background-color: #aaa;
            position: relative;
        }
        .active{
            background-color: #5cc;
        }
        .delete{
            background-color: #c53;
            width: 16px;
            height: 16px;
            border-radius: 50%;
            display: none;
            position: absolute;
            top: -4px;
            right: -4px;
            display: none;
            justify-content: center;
            align-items: center;
            cursor: pointer;
        }
        .name:hover>.delete{
            display: flex;
        }
    </style>
<script>
    let vm = new Vue({
        el:'#App',
        data:{
            add:'',
            name: '',
            classList: ['张三','赵四','吴亦凡','罗志祥','李易峰','文章','光头强','熊大','熊二','鸣人','佐助','卡卡西','春野樱','井野','大和','鹿丸','雏田'],
            list:[]
        },
        watch: {
        },
        mounted(){},
        methods: {
            adds(){
                console.log(this.name, 11112222)
                if(!this.name){
                    alert('请输入名称')
                    return
                }
                this.classList.push(this.name)
                this.name = ''
            },
            callTheRoll(){
                if(this.list.length == this.classList.length){
                    alert('点名完成')
                    this.ToCallTheRoll()
                    return
                }
                let arr = this.classList.filter((value)=> !this.list.includes(value))
                this.list.push(arr[Math.trunc(Math.random()*arr.length)])
                this.add = this.list[this.list.length-1]
                setTimeout(()=>{
                    this.add = ''
                },1000)
            },
            ToCallTheRoll(){
                this.list = []
            },
            deleteName(name){
                this.classList = this.classList.filter((value)=> !(name == value))
            }
        }
    })
</script>

 

标签:点名,name,classList,list,value,add,添加,随机,display
From: https://www.cnblogs.com/szx911/p/16745665.html

相关文章

  • threejs-模型点击以及添加CSS2DObject
    模型点击事件网上教程挺多的,官网好像也有demo,这里我就只记录我碰到的问题以及解决方案:首先要清楚一件事,就是模型的展示需要一个容器,当这个容器是body|window和非全屏的......
  • uniapp微信小程序添加更新检测
    App.vue:可以放在onShow:热启动(后台进入前台)和onLaunch:冷启动(重启小程序)下constupdateManager=uni.getUpdateManager();updateManager.onCheckForUpdate(function(......
  • 如何修改redis配置文件(添加密码验证)
    操作步骤:1:找到redis的配置文件,2:停止redis服务,3:修改配置文件,4启动服务1,找到redis的配置文件首先直接试试whereisredis.conf 看能不能返回路径试过2个不同......
  • IDEA添加多个git地址,同时提交两个git地址代码
     添加git地址            选择要提交的git地址即可......
  • ECharts柱状图,随机或者指定改变颜色
    //指定颜色itemStyle:{color:function(params){varcolorarrays=["#990033","#ff66cc","#3300cc","#ffcc00","#339933","#66cccc"]......
  • C#制作一个随机生成验证码程序
    制作一个随机生成验证码程序一、验证码类namespaceRVaildateCode{publicclassClass1{publicvoidCreateCheckCodeImage(PictureBoxpbox)......
  • 将程序添加为Linux系统服务
     将程序注册为系统服务后,可通过systemctl和service系统命令启动,查看,停止程序,并可以将程序设置为开机自启动等等。将程序注册为系统服务,需要编辑xxx.service文件,......
  • Linux 用户组管理#01:添加用户到组、移除组的用户
    添加用户到组usermodusermod[options]LOGINLOGIN:修改的用户;-G:移到某个组;把test用户移到zrf用户组中:zrf@ubuntu:~$sudousermod-Gzrftestzrf@ubuntu:~$......
  • 随机数生成
    我知道是伪随机数生成啦你不要再说啦mt19937c++11加入。定义一个名叫rd的随机数生成器(括号内为种子)。mt19937rd(std::chrono::system_clock::now().time_since_epo......
  • python 生成伪随机数函数 random
    """random函数:出一个伪随机数具体怎么做?一般我们会考虑先查找python官方自带的文档在IDLE的右上角点击HELP-->PythonDoc(F1)-->点击左上角的索引-->输入我们要......