Home  >  Article  >  Web Front-end  >  js implements simple single-number random lottery (0-9)_javascript skills

js implements simple single-number random lottery (0-9)_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:47:221705browse
The web page special effect shared in this article is a digital lottery game that can be controlled to start and stop, similar to the digital lottery games on many TVs. Here is all the code I shared:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>简易的单数字随机抽奖,抽取随机数的js特效代码</title>
</head>
<body>
<div id="num"></div>
<input value="start" id="start" type="button" />
<input value="stop" id="stop" type="button" />
<script>
var num = document.getElementById("num");
var start = document.getElementById("start");
var _stop = document.getElementById("stop");
var intv = null;
start.onclick = function(){
 
 if(intv==undefined){
 
 intv = setInterval(function(){num.innerHTML = Math.floor(Math.random()*10);},50);
 
 }
 
}
_stop.onclick = function(){
 
 clearInterval(intv);
 
 intv=null;
 
}
</script>
</body>
</html>
Operation rendering:
Initial state:
After starting:

What I am showing now is a screenshot of the operation, which is still. You can operate it and feel it, and you will feel a little sense of accomplishment.

The above is the entire content of this article. I hope you can continue to study in depth.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn