Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 15:47:22
Original
1652 people have browsed it
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>
Copy after login
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.

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!