当前位置: 首页 > news >正文

前端学习之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 = ['宝马五元代金卷','兰博基尼五元代金卷','法拉利五元代金卷','iphone五元代金卷']    //抽奖逻辑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>

结果


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

http://www.lryc.cn/news/336506.html

相关文章:

  • 解决windows下Qt Creator显示界面过大的问题
  • MySQL 通信协议 tcp c/s架构 jdbc java
  • 蓝桥杯第十三届电子类单片机组决赛程序设计
  • 【Entity Framework】如何使用EF中的生成值
  • 【MATLAB源码-第185期】基于matlab的16QAM系统相位偏移估计EOS算法仿真,对比补偿前后的星座图误码率。
  • C++入门语法(命名空间缺省函数函数重载引用内联函数nullptr)
  • 9.vector的使用介绍和模拟实现
  • 探索设计模式的魅力:MVVM模式在AI大模型领域的创新应用-打破传统,迎接智能未来
  • Docker使用— Docker部署安装Nginx
  • C/C++基础----运算符
  • YOLOv9:下一代目标检测的革新
  • Leetcode算法训练日记 | day20
  • conda创建虚拟环境太慢,Collecting package metadata (current_repodata.json): failed
  • Tensorflow(GPU版本配置)一步到位!!!
  • STL之map
  • 闲谈2024(一)
  • SQL注入利用 学习- 布尔盲注
  • 前端项目部署教程——有域名有证书
  • 《看漫画学C++》第12章 可大可小的“容器”——向量
  • OpenAI推出GPTBot网络爬虫:提升AI模型同时引发道德法律争议
  • Claude使用教程
  • 【经典算法】LeetCode25:K 个一组翻转链表(Java/C/Python3,Hard)
  • 6.11物联网RK3399项目开发实录-驱动开发之定时器的使用(wulianjishu666)
  • 算法训练营第二十三天(二叉树完结)
  • mysql主从复制Slave_SQL_Running: No
  • 【SpringBoot】SpringBoot项目快速搭建
  • Terraform 状态不同步处理
  • 4.2.k8s的pod-标签管理、镜像拉取策略、容器重启策略、资源限制、优雅终止
  • 能源党建后台项目总结
  • 股票高胜率的交易法则是什么?