Make a random number selection page

Use Math objects to generate random integers between 1 and 60

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>选号器</title>
	</head>
	<style type="text/css">
		.inputTxt{
			height: 500px;
			width: 600px;
			font-size: 360px;
			text-align: center;
		}
	</style>
	<body>
		<center>
			<form name="myForm">
				<input name="myText" type="text" value="0" class="inputTxt" id="in1" />
				<input name="start" type="button" value="开始" onclick="startScroll()" />
				<input name="stop" type="button" value="停止" onclick="stopScroll()" />
			</form>
		</center>
		<script type="text/javascript">
			var timer;
			//点击开始按钮
			function startScroll(){
				//产生1~60之间的随机整数
				var num=Math.floor(Math.random()*60+1); 
				//document.getElementById("in1").value=num;  //第一种写法
				document.myForm.myText.value=num;  //第二种写法
				//使用定时器函数,60毫秒调用函数
				timer=setTimeout("startScroll()",60);
			}
			//点击停止按钮
			function stopScroll(){
				//清除定时器
				clearTimeout(timer);	
			}
		</script>
	</body>
</html>
Published 19 original articles · praised 20 · visits 497

Guess you like

Origin blog.csdn.net/Handsome_gir/article/details/105185614