最新回答 / 破舊的時(shí)光機(jī)3662066
通過判斷瀏覽器是否支持dom2 來判定瀏覽器類別 然后采用不同的事件處理方法,支持dom2的就用addelementlistener,不然就用dom0,還不行就用ie的catchevent
2017-09-30
感覺還是用seclect元素好點(diǎn),不然感覺好亂,而且鼠標(biāo)滑過效果的話用css的hover屬性好像也可以實(shí)現(xiàn)啊
2017-09-28
<html>
<title>抽獎(jiǎng)</title>
<head>
<script type="text/javascript">
var data=["空調(diào)","風(fēng)扇","洗衣機(jī)","微波爐","手機(jī)","電腦","謝謝惠顧","電視機(jī)"],
timer=null;
function startw(){
<title>抽獎(jiǎng)</title>
<head>
<script type="text/javascript">
var data=["空調(diào)","風(fēng)扇","洗衣機(jī)","微波爐","手機(jī)","電腦","謝謝惠顧","電視機(jī)"],
timer=null;
function startw(){
2017-09-26
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">獎(jiǎng)品</div><button id="start" onClick="startw()" > 開始</button><button id="end" onClick="endw()" > 結(jié)束</button></body></html>
2017-09-26
再就是按鈕通常直接用<input type="button"></input>或者<button></button>然后在添加鼠標(biāo)點(diǎn)擊和鍵盤點(diǎn)擊事件,這樣會(huì)少寫很多代碼和邏輯。
2017-09-26
解決鍵盤開始暫停:
1、鼠標(biāo)點(diǎn)擊開始之后按鈕變?yōu)椴豢捎?,點(diǎn)擊結(jié)束后開始按鈕可用。
2、點(diǎn)擊鍵盤判斷開始按鈕是否可用,不可用則觸發(fā)結(jié)束按鈕,可用則觸發(fā)開始按鈕。
3、問題解決
1、鼠標(biāo)點(diǎn)擊開始之后按鈕變?yōu)椴豢捎?,點(diǎn)擊結(jié)束后開始按鈕可用。
2、點(diǎn)擊鍵盤判斷開始按鈕是否可用,不可用則觸發(fā)結(jié)束按鈕,可用則觸發(fā)開始按鈕。
3、問題解決
2017-09-26
點(diǎn)擊開始之后按鈕變?yōu)椴豢牲c(diǎn)擊狀態(tài)不就可以了么?
2017-09-26
最新回答 / 破舊的時(shí)光機(jī)3662066
把script放在body最后 ,你放在開頭domready沒有完成不會(huì)執(zhí)行當(dāng)然你也可以用window.onload 或者jqeury的ready來完成。具體原因可以看慕課DOM探索之基礎(chǔ)詳解篇。html文件里的東西從上往下從左往右解析讀到哪解析到哪,放在前面先執(zhí)行了script里的但是下面的dom樹還沒生成找不到btn所以就會(huì)沒有反應(yīng)
2017-09-23