Javascript implements a keyboard-controllable lottery system and a javascript lottery.
Create a simple lottery system! Welcome to learn!
JS principle: Create an array to store lottery content, such as iPhone 6. When you click it, enable the timer to generate a random number and change innerHTML of the corresponding text to the content of the array.
To increase the chance of a lottery, you can repeat a value in the array multiple times. Next, let's look at the code. ,
JavaScript code
Window. onload = function () {var data = ["iphone 6 s plus", "Apple Mac laptop", "Meimei Washing Machine", "lingmei pen", "Thank you for your participation ", "Sony in-ear headphones", "leibai mechanical keyboard", "javaScript Advanced Programming Design", "exquisite Mug", "Winnie the Pooh", "500 yuan Sinopec fuel card ", "iQiYi annual membership", "iPad mini", "32g u disk",]; var bStop = true; var timer = null; var btns = document. getElementById ('dns '). getElementsByTagName ('span '); var text = document. getElementById ('text'); btns [0]. onclick = start; btns [1]. onclick = stop; document. onkeyup = function (event) {event = event | window. event; if (event. keyCode = 13) {if (bStop) {start () ;}else {stop () ;}} function start () {clearInterval (timer ); timer = setInterval (function () {var r = Math. floor (Math. random () * data. length); text. innerHTML = data [r] ;}, 20); btns [0]. style. background = '#666'; bStop = false;} function stop () {clearInterval (timer); btns [0]. style. background = 'blue'; bStop = true ;}}
Html css code:
<! DOCTYPE html>
I hope this article will help you learn and easily implement the lottery system.
Articles you may be interested in:
- Easily create a simple lottery system using Javascript
- JavaScript lottery effect implementation code
- Javascript random lottery code
- Code for simulating lottery order in JS
- Js and html5 are compatible with android/IOS
- Javascript lottery code Effects
- JavaScript to implement a simple random lottery
- Js Implementation of big turntable lottery game instances