其他分享
首页 > 其他分享> > 随机点名(数组)

随机点名(数组)

作者:互联网

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			#box{
				background-color: greenyellow;
				height: 80px;
				width: 150px;
				margin: 50px auto;
				text-align: center;
				font-size: 30px;
				line-height: 80px;
			}
			#box1{
				background-color: gainsboro;
				height: 40px;
				width: 80px;
				margin: 0 auto;
				border-radius: 15px;
				text-align: center;
				font-size: 20px;
				line-height: 40px;
			}
		</style>
	</head>
	<body>
		<div id="box">一会吃什么</div>
		<div id="box1" οnclick="" >开始</div>
	</body>
	<script>		 	 
		var obox=document.getElementById("box");
		var obox1=document.getElementById("box1");
		var lucky=new Array("牛肉饭","鸡肉饭","麻辣烫","食堂","泡面","手抓饼","炒面","辣肉拌面","牛肉汤");
		var a=1;
		var fn=null;
		 
		obox1.οnclick=function(){
			if(a==1){
				fn=setInterval(function(){
				var randomName=Math.round(Math.random()*(lucky.length-1));
				obox.innerHTML=lucky[randomName];},50);
				obox1.innerHTML="就它了";
				a=4;
			
		}else{
			clearInterval(fn);
			obox1.innerHTML="换一个";
			a=1;
		}
		}
		
	
		
		
		
	</script>
</html>

标签:点名,innerHTML,lucky,obox1,height,80px,随机,数组,var
来源: https://blog.csdn.net/weixin_43951248/article/details/100862384