web前端第三次作业

一、使用js完成抽奖项目效果和内容自定义

代码如下:

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>抽奖活动</title>
    <style>
       body {
            font-family: "黑体";
            text-align: center;
            margin-top: 180px;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            margin: 10px;
            cursor: pointer;
            border: none;
            border-radius: 5px;
        }
        #start{
            background-color: palevioletred;
            color: white;
        }
        #end{
            background-color: deepskyblue;
            color: white;
        }
        #wp{
            font-family: "黑体";
            margin-top: 50px;
            font-size: 30px;     
        }
    </style>
</head>
<body>
    <h1>随机抽奖活动</h1>
    <button id="start">开始</button>
    <button id="end">结束</button>
    <div id="wp">中奖物品</div>
    <script>
        var ostart=document.getElementById('start');
		var oend=document.getElementById('end');
		var otxt=document.getElementById('wp');
        var timer;
			var m;
			var list=['平板','现金200元','pad','购物卡','手机','购物卡','音响','电动车','现金200元','谢谢','谢谢','谢谢','谢谢','谢谢','谢谢','谢谢']
			// 开始
			ostart.onclick=function(){
				timer=setInterval(function(){
					// 产生随机数
					m=parseInt(Math.random()*list.length);
					// 修改html
					otxt.innerHTML=list[m]
					// 修改图片 .setAttribute('src',list[m])
				},1000)
			}
			// 停止
			oend.onclick=function(){	
				clearInterval(timer);
				alert('恭喜抽中'+list[m]);
				list.splice(m,1,'谢谢');
			}
    </script>
</body>
</html>

效果如下:

二、每日一讲视频

每日一讲

相关推荐
梦帮科技3 小时前
Node.js配置生成器CLI工具开发实战
前端·人工智能·windows·前端框架·node.js·json
VT.馒头4 小时前
【力扣】2695. 包装数组
前端·javascript·算法·leetcode·职场和发展·typescript
css趣多多4 小时前
一个UI内置组件el-scrollbar
前端·javascript·vue.js
C澒4 小时前
前端整洁架构(Clean Architecture)实战解析:从理论到 Todo 项目落地
前端·架构·系统架构·前端框架
C澒4 小时前
Remesh 框架详解:基于 CQRS 的前端领域驱动设计方案
前端·架构·前端框架·状态模式
Charlie_lll4 小时前
学习Three.js–雪花
前端·three.js
onebyte8bits5 小时前
前端国际化(i18n)体系设计与工程化落地
前端·国际化·i18n·工程化
C澒5 小时前
前端分层架构实战:DDD 与 Clean Architecture 在大型业务系统中的落地路径与项目实践
前端·架构·系统架构·前端框架
BestSongC5 小时前
行人摔倒检测系统 - 前端文档(1)
前端·人工智能·目标检测
0思必得05 小时前
[Web自动化] Selenium处理滚动条
前端·爬虫·python·selenium·自动化