var start=document.getElementById("start");
var end=document.getElementById("end");
var word=document.getElementById("text");
start.disabled=true;
timer=setInterval(function(){
var random= Math.floor(Math.random()*data.length);
word.innerHTML=data[random];
},50)
end.disabled=false;
var end=document.getElementById("end");
var word=document.getElementById("text");
start.disabled=true;
timer=setInterval(function(){
var random= Math.floor(Math.random()*data.length);
word.innerHTML=data[random];
},50)
end.disabled=false;
2017-09-26
}
function endw(){
var start=document.getElementById("start");
var end=document.getElementById("end");
end.disabled=true;
clearInterval(timer);
start.disabled=false;
}
document.onkeydown=function(){if(start.disabled){
function endw(){
var start=document.getElementById("start");
var end=document.getElementById("end");
end.disabled=true;
clearInterval(timer);
start.disabled=false;
}
document.onkeydown=function(){if(start.disabled){
2017-09-26
document.onkeyup=function(event){if(event.keyCode==13){endw();}}}else{document.onkeyup=function(event){if(event.keyCode==13){startw();}}}}</script></head><body><div id="text">獎品</div><button id="start" onClick="startw()" > 開始</button><button id="end" onClick="endw()" > 結束</button></body></html>
2017-09-26
再就是按鈕通常直接用<input type="button"></input>或者<button></button>然后在添加鼠標點擊和鍵盤點擊事件,這樣會少寫很多代碼和邏輯。
2017-09-26
解決鍵盤開始暫停:
1、鼠標點擊開始之后按鈕變為不可用,點擊結束后開始按鈕可用。
2、點擊鍵盤判斷開始按鈕是否可用,不可用則觸發結束按鈕,可用則觸發開始按鈕。
3、問題解決
1、鼠標點擊開始之后按鈕變為不可用,點擊結束后開始按鈕可用。
2、點擊鍵盤判斷開始按鈕是否可用,不可用則觸發結束按鈕,可用則觸發開始按鈕。
3、問題解決
2017-09-26
感覺抽獎系統這一章節有些跑題了,講了一堆計時器、隨機數。真的要講鍵盤事件的話,寫一個文本輸入框,限制可以打多少字,這樣更明顯也更容易理解。
2017-09-18