Home >Web Front-end >JS Tutorial >JS implements Ferris wheel lottery

JS implements Ferris wheel lottery

php中世界最好的语言
php中世界最好的语言Original
2018-05-03 15:55:102386browse

This time I will bring you JS to implement the Ferris wheel lottery. What are the precautions for JS to implement the Ferris wheel lottery? The following is a practical case, let's take a look.

Rendering:

Picture material:

The code is as follows, copy and use:

<!DOCTYPE html>
<html>
<head lang="en">
 <meta charset="UTF-8">
 <title>幸运抽奖页面</title>
 <style>
  /*CSS代码*/
  *{
   padding:0;
   margin:0;
  }
  .login-box{
   width:500px;
   height:430px;
   /* border:1px solid red;*/
   /*水平居中*/
   margin:100px auto;
       <!-- 此处需要修改为自己的图片路径 -->
   background: url(img/tx1.png) no-repeat;
   box-shadow: 0 0 2px rgba(0,0,0,.5);
  }
  .login{
   padding:5px;
   border:0 none;
   background: #0a88e1;
   color: white;
   font-size:12px;
   text-align: center;
   width:220px;
   line-height: 20px;
   margin-top:200px;
   margin-left:120px;
  }
 </style>
</head>
<body>
 <p class="login-box">
  <input type="button" value="点击开始抽奖" class="login" id="luckbtn" onclick="luck()"/>
 </p>
</body>
<script>
 //JS代码:幸运抽奖
 var no = prompt("请输入您的四位会员卡号:");
 //获取到抽奖按钮
 document.getElementById("luckbtn").value =no+"-欢迎你,点击开始抽奖" ;
 //当点击抽奖按钮的时候调用,幸运抽奖的规则及提醒,功能 function 函数
 function luck(){
  //系统随机生成一个0-10之间的随机整数 :Math.random() 0-1之间的浮点数
  var num = parseInt(Math.random()*10);
  /*alert(num);*/
  //随机数=会员卡号的百位数
  /* var gewei = no%10;
  alert(gewei);*/
  /*var shiwei = parseInt(no/10%10);
  alert(shiwei);*/
  var baiwei = parseInt(no/100%10);
  /*alert(baiwei);*/
  if(baiwei == num){
   alert("恭喜"+no+",您中奖了!");
  }else{
   alert("对不起,"+no+",您没有中奖!");
  }
 }
</script>
</html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Detailed explanation of the use of JS event delegation

Detailed explanation of the use of computed in Vue.js

The above is the detailed content of JS implements Ferris wheel lottery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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