Javascript implements a keyboard-controllable lottery system and a javascript lottery.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.