math.float是取整
Dom键盘事件
键盘事件:
keyDown、keyPress、keyUp
键盘触发事件
var random=Math.random();//生成随机数0-1之间的浮点数
console.log("random")//打印random
Math.floor(Math.random()*data.length)//0~7之间的随机数取整
键盘事件~~~键盘事件~~~
键盘事件哦
keyDown:当用户按下键盘上的任意键时触发,而且如果按住不放的话,会重复触发此事件
keyPress:当用户按下键盘上的字符键时触发,而且如果按住不放的话,会重复触发此事件
keyUp:当用户释放键盘上的键时触发
var data=['Phone5','Ipad','三星笔记本','佳能相机','惠普打印机','谢谢参与','50元充值卡','1000元超市购物券'],
timer=null;
window.onload=function(){
var play=document.getElementById('play'),
stop=document.getElementById('stop');
// 开始抽奖
play.onclick=playFun;
function playFun(){
var title=document.getElementById('title');
var play=document.getElementById('play');
clearInterval(timer);
timer=setInterval(function(){
var random=Math.floor(Math.random()*data.length);
title.innerHTML=data[random];
},50);
play.style.background='#999';
}
PS:
css{cursor:pointer}定義光標為手型
js:console.log("random")//打印random
Math.floor(Math.random()*數組的長度8)//0~7之間的隨機數取整
JavaScript can "display" data in different ways:
Writing into an alert box, using window.alert().
Writing into the HTML output using document.write().
Writing into an HTML element, using innerHTML.
Writing into the browser console, using console.log().
键盘事件