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

点名

<!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_statusclearInterval(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; *//* padding: 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= 0let div1 = document.querySelector('.cirle')let t1 = document.querySelector('.time1')let t2 = document.querySelector('.time2')time1 = 0let 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+1t2.textContent = time1// 当秒数够一分钟,分针数加1if(time1%60==0){time2 = time2+1t1.textContent = time2}}// 重置button3.onclick = function(){time1 = 0time2 = 0t1.textContent = time2t2.textContent = time1clearInterval(id)}</script>
</body>
</html>

结果

 


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

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

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

声明式事务

文章目录 1.事务分类1.传统方式解决事务2.声明式事务 2.声明式事务案例1.需求分析2.解决方案分析3.数据表创建4.编写GoodsDao.java1.编写配置文件JdbcTemplate_ioc.xml2.单元测试 5.编写GoodsService.java6.配置事务管理器JdbcTemplate_ioc.xml7.进行测试 3.debug事务管理器Dat…

2. 链表

链表的概念及结构 概念&#xff1a;链表是⼀种物理存储结构上⾮连续、⾮顺序的存储结构&#xff0c;数据元素的逻辑顺序是通过链表中的指针链接次序实现的 。 链表的结构跟⽕⻋⻋厢相似&#xff0c;淡季时⻋次的⻋厢会相应减少&#xff0c;旺季时⻋次的⻋厢会额外增加⼏节。…

@NameBinding注解名称绑定过滤器/拦截器

NameBinding注解名称绑定过滤器/拦截器&#xff0c;只针对某一些资源方法执行处理逻辑 一、为什么要用名称绑定 一般情况下&#xff0c;借助Spring的过滤器或者拦截器等对Http请求或响应进行处理就能满足需求。但是在有些场景下若只需对特定的xxxResource做拦截处理&#xff0…

【ARM Trace32(劳特巴赫) 使用介绍 12.1 -- Trace32 读写 64位地址】

请阅读【Trace32 ARM 专栏导读】 文章目录 Trace32 读写 64位地址读 64 位地址写64位地址Trace32 读写 64位地址 在使用TRACE32进行调试时,有时需要读取或操作64位的地址,特别是在处理64位的处理器或操作系统时。以下是如何在TRACE32中读取64位地址的一般方法。 读 64 位地…

vue-element-admin vue设置动态路由 刷新页面后出现跳转404页面Bug 解决方法

做项目时遇到的这个bug&#xff0c;因为除了跳404之外也没太大影响&#xff0c;之前就一直放着没管&#xff0c;现在项目基本功能实现了&#xff0c;转头处理了一下&#xff0c;现在在这里记录一下解决方法 这个bug的具体情况是&#xff1a;设置了动态路由之后&#xff0c;不同…

FPGA - ZYNQ 基于Axi_Lite的PS和PL交互

前言 在FPGA - ZYNQ 基于EMIO的PS和PL交互中介绍了ZYNQ 中PS端和PL端交互的开发流程&#xff0c;接下来构建基于基于Axi_Lite的PS和PL交互。 开发流程 Axi_Lite从机 在FPGA - AXI4_Lite&#xff08;实现用户端与axi4_lite之间的交互逻辑&#xff09;中&#xff0c;详解介绍…

微信小程序:基于MySQL+Nodejs的汽车品牌管理系统

各位好&#xff0c;接上期&#xff0c;今天分享一个通过本地MySQLNodejs服务器实现CRUD功能的微信小程序&#xff0c;一起来看看吧~ 干货&#xff01;微信小程序通过NodeJs连接MySQL数据库https://jslhyh32.blog.csdn.net/article/details/137890154?spm1001.2014.3001.5502 …

针对窗口数量多导致窗口大小显示受限制的问题,使用滚动条控制窗口

建议&#xff1a;首先观察结果展示&#xff0c;判断是否可以满足你的需求。 目录 1. 问题分析 2. 解决方案 2.1 界面设计 2.2 生成代码 2.3 源码实现 3. 结果展示 1. 问题分析 项目需要显示的窗口数量颇多&#xff0c;主界面中&#xff0c;如果一次性显示全部窗口&#x…

飞书小技巧:markdown导出

文章目录 下载Feishu2Md飞书应用配置配置feishu2md工具绑定应用导出markdown 下载Feishu2Md Feishu2Md 飞书应用配置 进入飞书开发者后台 https://open.feishu.cn/app。 点击“创建企业自建应用”&#xff0c;并填写应用名称等信息。而后点击创建。 PS: 此处作者创建应用名…

面向对象设计与分析40讲(25)中介模式、代理模式、门面模式、桥接模式、适配器模式

文章目录 门面模式代理模式中介模式 之所以把这几个模式放到一起写&#xff0c;是因为它们的界限比较模糊&#xff0c;结构上没有明显的差别&#xff0c;差别只是语义上。 这几种模式在结构上都类似&#xff1a; 代理将原本A–>C的直接调用变成&#xff1a; A–>B–>…

网渲应用领域有哪些?渲染100邀请码1a12

网渲是一种利用云计算技术把本地渲染上传到云端进行的过程&#xff0c;它极大提高了渲染效率&#xff0c;摆脱了本地限制&#xff0c;使用网渲的领域有很多&#xff0c;这里我们列举下。 1、影视制作 在影视制作当中&#xff0c;对于需要大量特效和动画效果的电影来说&#x…

【STM32】嵌入式实验二 GPIO 实验:数码管

实验内容&#xff1a; 编写程序&#xff0c;在数码管上显示自己的学号。 数码管相关电路&#xff1a; PA7对应的应该是段码&#xff0c;上面的图写错了。 注意&#xff1a;选中数码管是低电平选中&#xff1b;并且用74HC595模块驱动输出的段码&#xff0c; 这个模块的学习可以…