Home >Web Front-end >JS Tutorial >js implements simple single-number random lottery (0-9)_javascript skills
<!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>
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.