前端学习之DOM编程案例:点名案例和秒表案例

news2024/9/30 5:33:24

点名

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点名案例</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <div id="container">
    </div>
    <script>
        let div0 = document.querySelector('#container')
        //最外边的大盒子
        div0.style.width = 800 +'px'
        div0.style.height = 900 +'px'
        div0.style.border = '1px dashed red'        
        div0.style.margin = 'auto'
        div0.style.textAlign = 'center'
        //抽奖显示的圆
        let cirle =  document.createElement('div')
        cirle.style.borderRadius = '50%'
        // cirle['borderRadius'] = '50%'
        // cirle['backgroundColor'] = 'red'
        cirle.style.backgroundColor = 'red'
        cirle.style.width = 300 + 'px'
        cirle.style.height = 300 + 'px'
        cirle.style.margin = 'auto'
        cirle.textContent = '点名系统'
        cirle.style.fontSize = '30px'
        cirle.style.color = 'white'
        cirle.style.marginTop = '80px'
        cirle.style.lineHeight = '300px'
        cirle.style.textAlign='center'
        div0.appendChild(cirle)
        //抽奖按钮
        let button1 = document.createElement('button')
        button1.style.width=300+'px'
        button1.style.height=40+'px'
        button1.textContent = '开始点名'
        button1.style.margin='auto'
        button1.style.marginTop = 40+'px'
        let btn_status = '开始点名'
        //奖品
        let arr = ['张三','李四','王五','周末']    
        //抽奖逻辑
        button1.onclick = function(){
            if (btn_status == '开始点名'){
            id = setInterval(start,10)
            }
            else{
                btn_status = '开始点名'
                button1.textContent = btn_status
                clearInterval(id)
            } 
        }
       
        div0.appendChild(button1)
        function start(){
            
                index = Math.ceil(Math.random()*4)
                cirle.textContent = arr[index]
                btn_status = '停止点名'
                button1.textContent = btn_status
            
            
        }
 
    </script>
</body>
</html>

结果

秒表

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定时器</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .div0{
            background-color: aqua;
            width: 400px;
            height: 500px;
            border: 1px dashed red;
            margin: auto;
            text-align: center;
        }
        .cirle{
            border-radius: 50%;
            background-color: red;
            width: 300px;
            height: 300px;
            margin: auto;
            display: grid;
            grid-template-columns: repeat(3,1fr);
        }
        button{
            margin-top: 20px;
            width: 100px;
            height: 40px;
            margin: auto;
            margin-top: 40px;
        }
        #time{
            width: 70px;
            height: 70px;
            /* background-color:black; */
            /* float: left; */
            margin: auto;
            /* margin-top: 100px; */
            /* pad
            ding: 10px; */
        }
        #time{
            line-height: 40px;
            font-size: 70px;
        }
    </style>
</head>
<body>
    <!-- 最外边蓝色大边框 -->
    <div class="div0">
        <!-- 红色圆 -->
        <div class="cirle">
            <!-- 秒数 -->
            <div id="time" class="time1">0</div>
            <div id="time" class="time0">:</div>
            <div id="time" class="time2">0</div>
        </div>
        <button class="button1">开始计时</button>
        <button class="button2">停止计时</button>
        <button class="button3">重置</button>
    </div>
    <script>
        let time2= 0
        let div1 = document.querySelector('.cirle')
        let t1 = document.querySelector('.time1')
        let t2 = document.querySelector('.time2')
        time1 = 0
        let button1 = document.querySelector('.button1')
        let button2 = document.querySelector('.button2')
        let button3 = document.querySelector('.button3')
        button1.onclick = function(){
            id = setInterval(time,1000)
        }
        // 停止
        button2.onclick = function(){
            clearInterval(id)
        }
        function time(){
            time1 = time1+1
            t2.textContent = time1
            // 当秒数够一分钟,分针数加1
            if(time1%60==0){
                time2 = time2+1
                t1.textContent = time2
            }
        }
        // 重置
        button3.onclick = function(){
            time1 = 0
            time2 = 0
            t1.textContent = time2
            t2.textContent = time1
            clearInterval(id)
        }
    </script>
</body>
</html>

结果

 


不嫌弃的点点关注,点点赞 ଘ(੭ˊᵕˋ)੭* ੈ✩‧

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1614397.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

C语言进阶课程学习记录-函数参数的秘密

C语言进阶课程学习记录-函数参数的秘密 实验实验小结调用约定实验-求平均数实验-可变参数的函数小结 本文学习自狄泰软件学院 唐佐林老师的 C语言进阶课程&#xff0c;图片全部来源于课程PPT&#xff0c;仅用于个人学习记录 实验 #include <stdio.h>int func(int i, int…

解线性方程组——追赶法解三对角方程组 | 北太天元

一、问题描述 对于线性方程组 A x b , A ( b 1 c 1 a 2 b 2 c 2 ⋱ ⋱ ⋱ ⋱ ⋱ ⋱ a n − 1 b n − 1 c n − 1 a n b n ) , b ( f 1 f 2 ⋮ f n ) Axb,\quad A\begin{pmatrix}b_1&c_1&&&&\\a_2&b_2&c_2&&&\\&\ddots&\d…

Unity导出package

C#代码导出后为一个dll&#xff0c;原有的不同平台的库不变。 以下操作均在build PC 平台下操作。 1.在要导出的文件夹下建assembly definition (Any platform) 2.将项目文件夹下的\Library\ScriptAssemblies中的相应assembly definition的dll复制到要导出的文件夹下 3.在uni…

Linux进阶篇:CentOS7搭建NFS文件共享服务

CentOS7搭建NFS文件共享服务 一、NFS介绍 NFS(Network File System)意为网络文件系统&#xff0c;它最大的功能就是可以通过网络&#xff0c;让不同的机器不同的操作系统可以共享彼此的文件。简单的讲就是可以挂载远程主机的共享目录到本地&#xff0c;就像操作本地磁盘一样&…

适用于摩托车仪表盘的液晶驱动IC:S1D15K01

S1D15K01j是EPSON的一款适用于适用摩托车混合数字仪表盘的车规混合液晶驱动IC。随着摩托车具备的特性和功能的逐渐增多&#xff0c;需要在仪表盘显示器上显示的信息量越来越大。另一方面&#xff0c;可用于显示的空间有限&#xff0c;需要有效地显示信息。在过去&#xff0c;摩…

《深入浅出多模态》: 多模态经典模型:BLIP

🎉AI学习星球推荐: GoAI的学习社区 知识星球是一个致力于提供《机器学习 | 深度学习 | CV | NLP | 大模型 | 多模态 | AIGC 》各个最新AI方向综述、论文等成体系的学习资料,配有全面而有深度的专栏内容,包括不限于 前沿论文解读、资料共享、行业最新动态以、实践教程、求职…

CANdb++数据库

1.理解主机厂定义的信号矩阵表 2.使用CANdb制作对应矩阵表中报文和信号dbc文件。 3.新建数据库 打开candb软件&#xff0c;点击文件&#xff0c;选择创建数据库&#xff0c;并选择数据库模版&#xff0c;本次测试选择CanTemplate.dbc模版&#xff0c;选择保存在本机中的位置&…

7.机器学习-十大算法之一拉索回归(Lasso)算法原理讲解

7.机器学习-十大算法之一拉索回归&#xff08;Lasso&#xff09;算法原理讲解 一摘要二个人简介三前言四原理讲解五算法流程六代码实现6.1 坐标下降法6.2 最小角回归法 七第三方库实现7.1 scikit-learn实现&#xff08;坐标下降法&#xff09;&#xff1a;7.2 scikit-learn 实现…

idea 中导入的项目maven不自动下载依赖包

导入之后不会自动引入依赖包&#xff0c;如下图&#xff0c;external libraries 下没有依赖 解决方案&#xff1a;重新更新下maven的Local repository 即可

STM32F030K6T6,基于值线ARM的32位MCU,具有16到64KB的闪存、定时器

STM32F030K6T6&#xff0c;ST/意法&#xff0c;基于值线ARM的32位MCU具有16到64KB的闪存、定时器 ADC&#xff0c;通信接口&#xff0c;2.4-3.6 V操作 STM32F030K6T6&#xff0c;ST/意法&#xff0c;基于值线ARM的32位MCU具有16到64KB的闪存、定时器 ADC&#xff0c;通信接口&…

一目了然:ipv4和ipv6的关键区别

ipv4和ipv6是互联网协议的两种版本&#xff0c;它们在多个方面存在显著差异。以下是这两种协议的具体差异&#xff1a; 1.地址长度和地址数量 IPv4使用32位地址&#xff0c;而IPv6使用128位地址。这意味着IPv6的地址空间比IPv4大约2^96倍&#xff0c;能够支持的IP地址数量远远…

深入理解VGG网络,清晰易懂

深入理解VGG网络 VGG网络是深度学习领域中一个非常经典的卷积神经网络&#xff08;CNN&#xff09;架构&#xff0c;由牛津大学的视觉几何组&#xff08;Visual Geometry Group&#xff09;提出。它在2014年的ImageNet挑战赛中取得了第二名的好成绩&#xff0c;并且在随后的许…

性能监控数据(本地、服务器)

CPU、内存、磁盘等的监控 一、mac本地性能监控 1. top 终端&#xff1a; top load Avg: 平均负载(1分钟&#xff0c;5 分钟&#xff0c;15 分钟)值不能超过 4&#xff0c;要不然就是超负荷运行 Tasks: 进程数 %Cpu(s): idle :剩余百分比 KiB Mem: free:剩余内存&#xff0…

古董展新风尚:山海鲸数据大屏引领科技潮流

在数字化浪潮的推动下&#xff0c;传统文化与现代科技正日益融合&#xff0c;展现出独特的魅力。近日&#xff0c;山海鲸推出了一款古董展览数据可视化大屏&#xff0c;将古董藏品的丰富内涵以直观、生动的形式呈现在观众面前&#xff0c;让人们在欣赏古董之美的同时&#xff0…

nvm报错获取 ‘https://npm.taobao.org/mirrors/node/index.json‘ 时失败

报错 如上图&#xff0c; 报错原因 由于npm.taobao.org域名HTTPS证书到期更换为npmmirror.com 解决 找到nvm安装路径的settings.txt文件 打开添加或者更改镜像地址&#xff0c;报存就好啦。如下 node_mirror: https://npmmirror.com/mirrors/node/ npm_mirror: https://…

[docker] 数据的持久化 - Volume bind mounts

[docker] 数据的持久化 - Volume & bind mounts docker 的数据笼统分类可以分为下面这三种&#xff1a; 只读数据 这种数据大多为源码、容器的配置文件&#xff0c;大多数情况下与镜像进行绑定 临时数据 这部分的数据大多数情况下与容器进行绑定&#xff0c;属于可写数据…

DRF 路由层

路由层 【1】原始路由 &#xff08;1&#xff09;正则re_path from django.urls import path, re_path from book import viewsurlpatterns [re_path(rbook/(?P<pk>\d)?/?$, views.BookAPIView.as_view(), namebook) ] 示例解释 (?P<pk>\d)是一个命名正…

使用mmsegmentaion遇到的问题

利用mmsegmentaion跑自定义数据集时的bug处理&#xff08;使用bisenetV2&#xff09; 1. ValueError: val_dataloader, val_cfg, and val_evaluator should be either all None or not None, but got val_dataloader{batch_size: 1, num_workers: 4}, val_cfg{type: ValLoop}, …

c++ 线性搜索与二分搜索

线性搜索 假设该项目以随机顺序存在于数组中&#xff0c;并且我们必须找到一个项目。那么搜索目标项目的唯一方法就是从第一个位置开始&#xff0c;并将其与目标进行比较。如果项目相同&#xff0c;我们将返回当前项目的位置。否则&#xff0c;我们将转移到下一个位置。…

在Qt creator中使用多光标

2024年4月22日&#xff0c;周一下午 Qt Creator 支持多光标模式。 多光标模式允许你在同一时间在多个光标位置进行编辑&#xff0c;从而可以更快地进行一些重复性的编辑操作。 要启用多光标模式&#xff0c;请按住 Alt 键&#xff0c;并用鼠标左键在文本编辑器中选择多个光标…