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

embedded/2024/10/18 16:49:00/

点名

<!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.ppmy.cn/embedded/9553.html

相关文章

软件行业中的蓝海领域有哪些?

一、什么是蓝海&#xff1f; 蓝海&#xff0c;指的是未知的市场空间。这个概念相对于“红海”而言&#xff0c;红海则是指已知的市场空间。 企业要启动和保持获利性增长&#xff0c;就必须超越产业竞争&#xff0c;开创全新市场&#xff0c;这其中包括两块&#xff1a;一块是…

【三维地图无人机路径规划】基于改进A星算法

课题名称&#xff1a; 基于改进A星算法的无人机三维地图路径规划 版本时间&#xff1a; 2024-04-22 程序运行&#xff1a; 直接运行AStar.m 文件即可 代码获取方式&#xff1a; QQ&#xff1a;491052175 VX&#xff1a;Matlab_Lover 改进方向&#xff1a; 预估函数增…

【学习笔记】Vue3源码解析:第三部分-获取computed的值;实现computed

课程地址&#xff1a;【已完结】全网最详细Vue3源码解析&#xff01;&#xff08;一行行带你手写Vue3源码&#xff09; 第三部分-获取computed的值&#xff1b;实现computed&#xff1a;&#xff08;对应课程的第18-21节&#xff09; 第22节&#xff1a;《获取computed的值》 …

35K的鸿蒙音视频开发岗位面经分享~

一个月前&#xff0c;阿里云在官网音视频终端 SDK 栏目发布适配 HarmonyOS NEXT 的操作文档和 SDK&#xff0c;官宣 MediaBox 音视频终端 SDK 全面适配 HarmonyOS NEXT。 此外&#xff0c;阿里云播放器 SDK 也在华为开发者联盟官网鸿蒙生态伙伴 SDK 专区同步上线&#xff0c;面…

阿里巴巴fastjson实现复制

以下为真实案例&#xff0c;供日常开发使用 package com.somnus.json;import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.somnus.custom.domain.Area; import com.somnus.custom.domain.Employee; import com.somnus.custom.domain.Empl…

主机连接本地VM虚拟机中的Ubuntu系统

虽然说本文特指Ubuntu系统&#xff0c;但过程原理也可以运用到类似的虚拟机上 前言 假设本机IPV4地址为10.26.231.99 1. 查看主机IP winr → 输入cmd → 点击确定&#xff0c;打开CMD → 输入ipconfig查看本地IPV4地址&#xff08;记下来&#xff09; 2. 虚拟机添加自动桥…

MySql 安装教程+简单的建表

目录 1.安装准备 1.MySQL官方网站下载 2.安装步骤 3.测试安装 4.简单的建表 1.安装准备 1.MySQL官方网站下载 下载安装包或者压缩包都可以 选择相应版本&#xff0c;点击Download开始通过网页下载到本地&#xff08;压缩包下载快一些&#xff09; 2.安装步骤 双击此.exe…

更换本地yum源的步骤

更换本地yum源的流程与命令&#xff1a;