基於JavaScript實現幸運抽獎頁面,javascript幸運抽獎

來源:互聯網
上載者:User

基於JavaScript實現幸運抽獎頁面,javascript幸運抽獎

 JS實現簡單的幸運抽獎頁面,供大家參考,具體內容如下

 :

圖片素材 :

代碼如下,複製即可使用:

<!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> <div class="login-box">  <input type="button" value="點擊開始抽獎" class="login" id="luckbtn" onclick="luck()"/> </div></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>

如果您有更好的方法或更多的功能,可以和我們大家一起分享哦,如有錯誤,歡迎聯絡我改正。

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援幫客之家。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.