每日一練--抽獎

抽獎界面的的製作

這裏寫圖片描述
用到的知識點:
一、Math.random()取得介於 0 到 1 之間的一個隨機數
二、1.直接丟棄小數部分,保留整數部分

a:parseInt(1.5555)
b: 0|1.5555

2.向上取整

a: Math.ceil(1.5555)
b: (1.5555+0.5).toFixed(0)
c: Math.round(1.5555+0.5)

3.向下取整

a: Math.floor(1.5555)
b: (1.5555-0.5).toFixed(0)
c:Math.round(1.5555-0.5)

4.四捨五入.
b:1.5555.toFixed(0)
c:Math.round(1.5555)

三、setTimeout() 只執行 code 一次。如果要多次調用,請使用 setInterval() 或者讓 code 自身再次調用 setTimeout()

四、鍵盤事件

var flag=0;
document.onkeyup=function(event){
              event = event || window.event;
              if(event.keyCode==13){
                 if(flag==0){
                   startFun();
                   flag=1;
                 }else{
                   stopFun();
                   flag=0;
                 }
              }
           }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章