Home Web Front-end JS Tutorial js simple lottery code_javascript skills

js simple lottery code_javascript skills

May 16, 2016 pm 04:19 PM
lottery

Core: js Math object and Array object

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>random</title>
 <style>
  #awardListDom{width: 100%;}
 </style>
</head>
<body>
 <label for="awardListDom">奖项列表</label><br>
 <input type="text" value="" id="awardListDom"> <br>
 <label for="num">抽到的奖</label><br>
 <input type="text" value="" id="num"> <br>
 <button id="submit">开始抽奖</button>
 <script>
  /* 
  * 思路:随机抽奖,抽一个奖项便减少一个
  * Math 对象方法:http://www.w3school.com.cn/jsref/jsref_obj_math.asp
  *  -random():返回 0 ~ 1 之间的随机数。
  *  -floor():获取整数
  * 数组操作:
  *  - splice(x,y); x:起始位置, y:获取并删除个数
  */

  function random(min,max){
    return Math.floor(min+Math.random()*(max-min));
  }
  var awardListDom=document.getElementById("awardListDom"),
  num=document.getElementById("num"),
  submit=document.getElementById("submit");
  var awardList=["一等奖","二等奖","二等奖","三等奖","三等奖","三等奖","鼓励奖","鼓励奖","鼓励奖","鼓励奖","谢谢参与","谢谢参与","谢谢参与","谢谢参与","谢谢参与","谢谢参与"];

  awardListDom.value=awardList;
  submit.onclick=function(){
   //引用数组
   var oldArray=awardList;
   var rNum=random(0,oldArray.length);
   
   if(oldArray.length<1){
    awardListDom.value="活动结束";
    num.value="活动结束";
   }
   else{
    num.value=oldArray[rNum];
    oldArray.splice(rNum,1);
    awardListDom.value=oldArray;
   }
  }
 </script>
</body>
</html>
Copy after login

demo:http://demo.jb51.net/js/2015/choujiang/

github:https://github.com/litengdesign/award

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1246
24
How to make an excel lottery applet How to make an excel lottery applet Mar 20, 2024 am 11:40 AM

In daily work, we encounter a lot of things that require drawing lots. The traditional method is to randomly draw numbers using paper numbers. With the development of electronic software, we can use computers to draw lots. The lesson I want to share with you today is How to make an excel lottery applet. 1. First, we open the Excel software and open the table we prepared. The table must contain our names. 2. Then we merge the cells on the right, fill in black who is lucky tonight, and merge the cells below and fill in red, as shown in the figure below. 3. Then we enter the randbetween function in the red area and set the first line to 2 and the last line to 7, as shown in the figure below. 4. Then we enter ind in front

Detailed explanation of the design and implementation of PHP lottery system Detailed explanation of the design and implementation of PHP lottery system Mar 01, 2024 am 09:51 AM

Detailed explanation of the design and implementation of PHP lottery system 1. Overview Lottery is a marketing tool used by many websites and applications. Through lottery, it can attract users to participate in activities, increase user interactivity and improve user stickiness. In this article, we will introduce in detail how to use PHP language to design and implement a simple lottery system. By studying this article, readers will understand the construction principles and specific code implementation of the lottery system. 2. System Design Before designing a lottery system, we first need to determine the functional requirements and processes of the system. one

How to use Vue to implement lottery wheel special effects How to use Vue to implement lottery wheel special effects Sep 19, 2023 am 10:18 AM

How to use Vue to implement lottery wheel special effects. As a popular marketing tool, lottery activities often appear in various activities. In order to increase fun and interactivity, we can use the Vue framework to implement a lottery wheel special effect. This article will introduce how to use Vue to achieve this special effect and give specific code examples. First, we need to create a Vue instance to control the status and animation of the turntable. In this example, we need to define the initial state of the wheel, including the prize list, whether the wheel is rotating,

Steps and techniques for developing lottery functions using PHP Steps and techniques for developing lottery functions using PHP Feb 29, 2024 pm 04:42 PM

Title: Steps and techniques for developing lottery functions using PHP. In website development, lottery functions are often used to increase user interactivity and attraction. Using PHP language to develop lottery functions is a common way. In this article, we will introduce how to use PHP to develop a simple lottery function and give specific code examples. Step 1: Prepare the database First, we need to create a MySQL database to store relevant data of the lottery, including prize information, participating user information, etc. You can use the following SQL command to create a

How to increase the winning rate in Douyin lottery? What are the techniques? How to increase the winning rate in Douyin lottery? What are the techniques? Mar 07, 2024 pm 02:43 PM

In today's prosperous era of social media, Douyin short videos have become an indispensable part of people's lives. The lottery on Douyin also attracted the attention and participation of countless users. However, many people often encounter a problem: How to improve their winning rate in Douyin lottery? This article will summarize several tips for increasing your winning rate to help you get more good luck in the Douyin lottery. 1. Read the lottery rules carefully. To increase the winning rate, we cannot ignore the lottery rules. Each lottery will have detailed rules, including participation conditions, lottery time and method, etc. Before participating, be sure to read the rules carefully and make sure you meet all conditions. Sometimes, you can also discover some hidden opportunities by carefully reading the rules, thereby increasing your chances of success.

The long sword cuts through the thunder in anger! 'Dragon Warrior' PC game will soon launch a new thunder and lightning profession - the fierce sword 'Thunder' The long sword cuts through the thunder in anger! 'Dragon Warrior' PC game will soon launch a new thunder and lightning profession - the fierce sword 'Thunder' Mar 01, 2024 pm 05:07 PM

The 2024 new expansion pack of "Dragon Warrior" "Fighting Sword and Thunder" will be officially launched on March 8! The thunderous thunder will not kill Wuming! The new and exciting career "Thunder" is coming! This new profession can rely on the power of thunder and lightning to turn thunder into blades, and use its unique thunder sword energy to divide the battlefield in battle. It has very powerful group burst damage and endurance, and will be used in team battles with its excellent displacement mechanism. Unparalleled strategic effect! The background story of the new profession Jing Lei is a female hero who is good at swordsmanship and possesses the mysterious ability connected with thunder and lightning. Able to integrate thunder and lightning spells and melee sword skills, and the sword swings are accompanied by lightning and thunder. From move to move, her sword skills are as fast and unpredictable as thunder. Each sword carries the power of thunder and lightning, making the enemy flee. Ran

How to implement lottery in php How to implement lottery in php Dec 19, 2022 am 10:10 AM

How to implement lottery in PHP: 1. Create a PHP sample file; 2. Define the prizes owned by the prize pool; 3. Conduct random lottery through the "shuffle($prize);" method; 4. Use "print_r($prize[0]) ;" Just print the lottery results.

How to use PHP to implement lottery draws and benefits in WeChat mini programs How to use PHP to implement lottery draws and benefits in WeChat mini programs Jun 02, 2023 am 10:51 AM

With the popularity of WeChat mini programs, more and more companies are beginning to conduct business through WeChat mini programs. Among them, lottery draws and welfare activities can not only enhance user stickiness, but also enhance corporate visibility. This article will introduce how to use PHP to implement lottery and welfare activities in WeChat mini programs. 1. Login to the WeChat applet First, we need to understand the login to the WeChat applet. In the WeChat mini program, if the user needs to log in, he must open the login authorization page provided by WeChat and agree to the authorization. Only then can we obtain the user's information and then perform extraction.

See all articles