资料
表格
制度
合同
管理
职场
经营
创业
范文
总结
计划
作文
文章
美文
词句
教程
模板
图片
字体
图标
办公
人事
财务
生产
管理资源吧首页
>>>
教程
>>>
编程
>>>
JavaScript教程
>>>
魔方在线秒表javascript版
效果如下图所以,我发现了,本人最短时间为0.06秒,看大家的键盘与反应了。
测试代码:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>魔方小站秒表 Stopwatch for Rubik's Cube China</title> </head> <style> td,input,div,th{font:9pt verdana} p {line-height:60%} </style> <body onkeyup="begin(event)" onkeydown="stop(event)" onload=rndCube()> <img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%20type%3Dtext%2Fjavascript%3E%20%0D%0Avar%20Max%3D25%3B%20%0D%0Avar%20bestAve%3B%20%0D%0Avar%20then%3B%20%0D%0Avar%20nowDec%3B%20%0D%0Avar%20nowBest%3B%20%0D%0Avar%20nowWorst%3B%20%0D%0Avar%20runing%3D0%3B%20%0D%0Avar%20timeint%3B%20%0D%0Avar%20i%3D0%3B%20%0D%0Avar%20totalsec%3B%20%0D%0Avar%20sec%3B%20%0D%0Avar%20min%3B%20%0D%0Avar%20subsec%3B%20%0D%0Avar%20secdis%3B%20%0D%0Avar%20mindis%3B%20%0D%0Avar%20subsecdis%3B%20%0D%0Avar%20datas%3Dnew%20Array()%20%0D%0Avar%20nowSecondes%3B%20%0D%0Afunction%20getAv(st%2Ced)%20%0D%0A%7B%20%0D%0Afor(i%3Dst%3Bi%3C%3Ded%3Bi%2B%2B)%20%0D%0A%7B%20%0D%0Adatas.join(%22%20%22)%20%0D%0A%0D%0A%7D%20%0D%0A%7D%20%0D%0A%0D%0Afunction%20stop(evt)%20%0D%0A%7B%20%0D%0Aif%20(runing%3D%3D1%20%26%26%20evt.keyCode%3D%3D32)%20%0D%0AclearTimeout(timeint)%3B%20%0D%0A%7D%20%0D%0Afunction%20toSeconds(dec)%20%0D%0A%7B%20var%20Ms%2Csec%20%0D%0Avar%20tmpDec%3Ddec.split(%22%3A%22)%20%0D%0Aif(tmpDec%5B0%5D*10%2F10%3E0)%20%0D%0A%7B%20%0D%0AMs%3DtmpDec%5B0%5D*60%20%0D%0Areturn(Ms%2BtmpDec%5B1%5D*10%2F10)%20%0D%0A%7Delse%7B%20%0D%0Areturn(tmpDec%5B1%5D*10%2F10)%20%0D%0A%7D%20%0D%0A%0D%0A%7D%20%0D%0A%0D%0Afunction%20begin(evt)%20%0D%0A%7B%20%0D%0Aif%20(evt.keyCode%3D%3D32)%20%0D%0A%7B%20%0D%0Aif%20(runing%3D%3D0)%7B%20%0D%0Athen%3Dnew%20Date()%3B%20%0D%0Aruning%3D1%3B%20%0D%0Ashow()%3B%20%0D%0A%7D%20%0D%0Aelse%20if%20(runing%3D%3D1)%20%0D%0A%7B%20%0D%0Aruning%3D2%3B%20%0D%0A%7D%20%0D%0Aelse%20%0D%0A%7B%20%0D%0AShowDatas(toSeconds(nowSeconds))%20%0D%0Adocument.getElementById(%22watch%22).innerHTML%3D%2200%3A00.00%22%3B%20%0D%0Aruning%3D0%3B%20%0D%0A%0D%0A%7D%20%0D%0A%7D%20%0D%0A%7D%20%0D%0Avar%20a%3D0%3B%20%0D%0Afunction%20ShowDatas(dec)%20%0D%0A%7B%20%0D%0Aif(dec%3D%3D0)%7Breturn%20false%7D%20%0D%0Avar%20newDec%3Dget2(dec)%20%0D%0Adatas.push(newDec)%20%2F%2F%E6%B7%BB%E5%8A%A0%E8%AE%B0%E5%BD%95%20%0D%0A%0D%0A%0D%0ASortDatas()%20%2F%2F%E6%8E%92%E5%BA%8F%E5%BE%97%E5%88%B0%E6%9C%80%E5%A4%A7%E6%9C%80%E5%B0%8F%E5%80%BC%20%0D%0AShowDetails()%20%0D%0AspanBest.innerHTML%3D%22%3Cb%20style%3Dcolor%3Ared%3E%22%2Bsec2minsec(nowBest)%2B%22%3C%2Fb%3E%22%20%0D%0AspanWorst.innerHTML%3D%22%3Cb%3E%22%2Bsec2minsec(nowWorst)%2B%22%3C%2Fb%3E%22%20%0D%0Avar%20tmp1%3D0%3B%20%0D%0Afor(i%3D0%3Bi%3Cdatas.length%3Bi%2B%2B)%20%0D%0A%7B%20%0D%0Atmp1%2B%3Ddatas%5Bi%5D%20%0D%0A%7D%20%0D%0A%0D%0AspanAv.innerHTML%3D%22%3Cb%3E%22%2Bsec2minsec(get2(tmp1%2Fdatas.length))%2B%22%3C%2Fb%3E%22%20%0D%0A%0D%0A%7D%20%0D%0Avar%20bestAve%3Dnew%20Array()%3B%20%0D%0Afunction%20sec2minsec(n)%20%0D%0A%7B%20if%20(n%3E60)%20%0D%0A%7B%20%0D%0Avar%20tmpmins%3DMath.floor(n%2F60)%3B%20%0D%0Avar%20tmpseconds%3Dget2(n-tmpmins*60)%3B%20%0D%0Avar%20tmpstring%20%0D%0Aif%20(tmpseconds%3C10)%20%0D%0A%7B%20tmpstring%3Dtmpmins%2B%22%3A0%22%2Btmpseconds%3B%20%0D%0A%7D%20%0D%0Aelse%20tmpstring%3Dtmpmins%2B%22%3A%22%2Btmpseconds%3B%20%0D%0Areturn%20tmpstring%20%0D%0A%7D%20%0D%0Aelse%20return%20n%3B%20%0D%0A%7D%20%0D%0Afunction%20ShowDetails()%20%0D%0A%7B%20%0D%0Aif(datas.length%3E12)%7Ba%3Ddatas.length%20-12%7D%20%0D%0Avar%20tmpTd%3D%22%3Ctable%20cellspacing%3D1%20bgcolor%3Dolive%3E%3Ctr%20align%3Dcenter%20bgcolor%3DEEEEEE%3E%3Cth%20width%3D50%3E1%3Cth%20width%3D50%3E2%3Cth%20width%3D50%3E3%3Cth%20width%3D50%3E4%3Cth%20width%3D50%3E%22%20%0D%0AtmpTd%2B%3D%225%3Ctd%20width%3D50%3E6%3Cth%20width%3D50%3E7%3Cth%20width%3D50%3E8%3Cth%20width%3D50%3E9%3Cth%20width%3D50%3E10%3Cth%20width%3D50%3E11%3Cth%20width%3D50%3E12%3C%2Ftr%3E%3Ctr%20bgcolor%3Dwhite%3E%22%3B%20%0D%0Afor(i%3Da%3Bi%3C(12%2Ba)%3Bi%2B%2B)%20%0D%0A%7B%20%0D%0AbestAve%5Bi-a%5D%3Ddatas%5Bi%5D%3B%2F%2F%E5%B0%86%E5%BD%93%E5%89%8D12%E5%B1%80%E6%88%90%E7%BB%A9%E5%AD%98%E5%85%A5%E6%95%B0%E7%BB%84%20%0D%0AtmpTd%2B%3D%22%3Ctd%20align%3Dcenter%3E%22%20%0D%0Aif(datas%5Bi%5D%3D%3Dundefined)%7BtmpTd%2B%3D%22-%22%7D%20%0D%0Aelse%20%0D%0A%7B%20%0D%0Aif(datas%5Bi%5D%3D%3DnowBest%20%7C%7C%20datas%5Bi%5D%3D%3DnowWorst)%20%0D%0A%7B%20%0D%0A%0D%0AtmpTd%2B%3Dsec2minsec(datas%5Bi%5D)%2B%22*%22%20%0D%0A%7Delse%20%0D%0A%7B%20%0D%0AtmpTd%2B%3Dsec2minsec(datas%5Bi%5D)%3B%20%0D%0A%7D%20%0D%0A%7D%20%0D%0AtmpTd%2B%3D%22%3C%2Ftd%3E%22%20%0D%0A%7D%20%0D%0AtmpTd%2B%3D%22%3C%2Ftr%3E%3C%2Ftable%3E%22%20%0D%0A%2F%2Falert(datas.join(%22%2C%22))%3B%20%0D%0Adiv1.innerHTML%3D%22%22%3B%20%0D%0Adiv1.innerHTML%3DtmpTd%3B%20%0D%0ArndCube()%3B%20%0D%0Adocument.focus()%3B%20%0D%0A%0D%0A%7D%20%0D%0Afunction%20show()%20%0D%0A%7B%20var%20now%3Dnew%20Date()%3B%20%0D%0Adiff%3Dnow.getTime()-then.getTime()%3B%20%0D%0Atotalsec%3DMath.floor(diff%2F1000)%3B%20%0D%0Asec%3Dtotalsec%2560%3B%20%0D%0Aif(sec%3C10)%20%0D%0A%7B%20%0D%0Asecdis%3D%220%22%2Bsec%3B%20%0D%0A%7D%20%0D%0Aelse%20%0D%0A%7B%20%0D%0Asecdis%3Dsec%3B%20%0D%0A%7D%20%0D%0Amin%3D(totalsec-sec)%2F60%3B%20%0D%0A%0D%0Aif%20(min%3C10)%20%0D%0A%7B%20%0D%0Amindis%3D%220%22%2Bmin%3B%20%0D%0A%7D%20%0D%0Aelse%20%0D%0A%7B%20%0D%0Amindis%3Dmin%3B%20%0D%0A%7D%20%0D%0A%0D%0Asubsec%3DMath.floor((diff%251000)%2F10)%3B%20%0D%0A%0D%0Aif%20(subsec%3C10)%20%0D%0A%7B%20%0D%0Asubsecdis%3D%220%22%2Bsubsec%3B%20%0D%0A%7D%20%0D%0Aelse%20%0D%0A%7B%20%0D%0Asubsecdis%3Dsubsec%3B%20%0D%0A%7D%20%0D%0AnowSeconds%3Dmindis%2B%22%3A%22%2Bsecdis%2B%22.%22%2Bsubsecdis%3B%20%0D%0Adocument.getElementById(%22watch%22).innerHTML%3DnowSeconds%3B%20%0D%0Atimeint%3DsetTimeout(%22show()%22%2C50)%20%0D%0A%7D%20%0D%0Afunction%20get2(dec)%20%2F%2F%E5%8F%96%E4%B8%A4%E4%BD%8D%E5%B0%8F%E6%95%B0%E7%82%B9%20%0D%0A%7B%20%0D%0Areturn%20Math.round(dec*100)%2F100%20%0D%0A%7D%20%0D%0A%0D%0Afunction%20SortDatas()%2F%2F%E6%9C%80%E5%A4%A7%E6%9C%80%E5%B0%8F%E5%80%BC%20%0D%0A%7B%20%0D%0Avar%20tmpArr%3Dnew%20Array()%20%0D%0Afor(i%3D0%3Bi%3Cdatas.length%3Bi%2B%2B)%20%0D%0A%7B%20%0D%0AtmpArr%5Bi%5D%3Ddatas%5Bi%5D%20%0D%0A%7D%20%0D%0AtmpArr.sort(function(a%2Cb)%7B%20return%20a-b%3B%7D)%20%0D%0AnowBest%3DtmpArr%5B0%5D%20%0D%0AnowWorst%3DtmpArr%5BtmpArr.length-1%5D%20%0D%0AShowBestAv()%20%0D%0A%7D%20%0D%0A%0D%0Afunction%20mycls()%20%0D%0A%7B%20%0D%0AclearTimeout(timeint)%3B%20%0D%0AnowSeconds%3D%2200%3A00%3A00%22%3B%20%0D%0Aruning%3D0%3B%20%0D%0Adatas%3Dnew%20Array()%3B%20%0D%0AShowDatas(0)%3B%20%0D%0AShowDetails()%3B%20%0D%0Adocument.getElementById(%22watch%22).innerHTML%3D%2200%3A00.00%22%3B%20%0D%0Abtn1.focus()%3B%20%0D%0A%0D%0A%0D%0A%7D%20%0D%0A%0D%0Afunction%20ShowBestAv()%20%0D%0A%7B%20%0D%0Avar%20av%3D0%3B%20%0D%0AbestAve.sort()%3B%20%0D%0Aif(bestAve%5B11%5D%3D%3Dundefined)%7Breturn%20false%7D%20%0D%0Afor(i%3D1%3Bi%3CbestAve.length-1%3Bi%2B%2B)%20%0D%0A%7B%20%0D%0Aav%2B%3DbestAve%5Bi%5D%3B%20%0D%0A%7D%20%0D%0AspanBestAv.innerHTML%3Dget2(av%2F10)%3B%20%0D%0A%2F%2Falert(bestAve)%20%0D%0A%0D%0A%7D%20%0D%0A%3C%2Fscript%3E"> <img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%3E%20%0D%0Afunction%20cancel()%20%0D%0A%7B%20clearTimeout(timeint)%3B%20%0D%0A%0D%0AnowSeconds%3D%2200%3A00%3A00%22%3B%20%0D%0A%0D%0Aruning%3D0%3B%20%0D%0Abtn1.focus()%3B%20%0D%0ArndCube()%3B%20%0D%0Adocument.getElementById(%22watch%22).innerHTML%3D%2200%3A00.00%22%3B%20%0D%0A%0D%0A%7D%20%0D%0Afunction%20rndCube()%20%0D%0A%7B%20%0D%0Avar%20move%3D%22%22%3B%20%0D%0Avar%20rndMove%3Dnew%20Array(%22R%22%2C%22L%22%2C%22F%22%2C%22B%22%2C%22U%22%2C%22D%22)%20%0D%0Avar%20add%3D0%3B%20%0D%0Avar%20tmpRnd%3B%20%0D%0Avar%20arr%3Dnew%20Array()%3B%20%0D%0Awhile(true)%20%0D%0A%7B%20%0D%0Aif(add%3E%3DMax)%7Bbreak%7D%20%0D%0A%2F%2FtmpRnd%3DMath.round(Math.random()*5)%20%0D%0Aif(tmpRnd%3D%3Darr%5Barr.length%20-1%5D)%20%0D%0A%7B%20tmpRnd%3DMath.floor(Math.random()*6)%3B%20%0D%0A%7D%20%0D%0Aelse%20%0D%0A%7B%20arr.push(tmpRnd)%20%0D%0Aadd%2B%2B%20%0D%0A%7D%20%0D%0A%0D%0A%7D%20%0D%0Afor(i%3D0%3Bi%3Carr.length%3Bi%2B%2B)%20%0D%0A%7B%20%0D%0Avar%20tmp%3DMath.floor(Math.random()*5)%20%0D%0Aif(tmp%3D%3D4)%20%0D%0A%7B%20move%2B%3DrndMove%5Barr%5Bi%5D%5D%2B%222%22%3B%7D%20%0D%0Aelse%20if(tmp%3D%3D2%20%7C%7C%20tmp%3D%3D3)%20%0D%0A%7B%20move%2B%3DrndMove%5Barr%5Bi%5D%5D%2B%22'%22%3B%7D%20%0D%0Aelse%20%0D%0A%7B%20move%2B%3DrndMove%5Barr%5Bi%5D%5D%3B%7D%20%0D%0Amove%2B%3D%22%20%22%3B%20%0D%0A%7D%20%0D%0A%0D%0A%0D%0ArndDiv.innerHTML%3Dmove%3B%20%0D%0A%7D%20%0D%0A%0D%0A%3C%2Fscript%3E"> <center> <div id="watch" style="filter:shadraw(x=1,y=1,color=black);position:relative;width: 359px; height: 80px ; font-size:48pt; font-family:Arial; font-weight:bold; color:navy; text-align:center" >00:00.00</div> <p> <font size="2">用<font color="#000080"><b>空格</b></font>键<b>开始</b>(松开时触发)、<b>停止</b>(按下时触发)、<b>复位</b>(同时记录成绩),enjoy:)</font></p> <p><b><font size="2" color="#FF0000">注意:</font></b><font size="2">请先最大化窗口或拉伸窗口使右边的滚动条不出现,否则空格键会让窗口滚动。</font></p> <p><font size="2">下面的记录系统是魔方吧的MAN大侠编写。</font> </p> <div id=rndDiv style="font:12pt Arial;font-weight:bold"></div> <input type=button value="清除所有记录" onclick=mycls();><input type=button value="不记录此次成绩" type=button onclick=cancel();div1.focus()> <input type=button value="" style="width:0px;height:0px" onclick="document.focus" id=btn1> <div id=div1> <table cellspacing=1 bgcolor=olive> <tr bgcolor=#EEEEEE align=center> <td width=50>1 <td width=50>2 <td width=50>3 <td width=50>4 <td width=50>5 <td width=50>6 <td width=50>7 <td width=50>8 <td width=50>9 <td width=50>10 <td width=50>11 <td width=50>12 </tr> <tr bgcolor=white align=center> <td width=50>- <td width=50>- <td width=50>- <td width=50>- <td width=50>- <td width=50>- <td width=50>- <td width=50>- <td width=50>- <td width=50>- <td width=50>- <td width=50>- </tr> </table> </div> </center> <table align=center> <tr><td>最快:</td><td><span id=spanBest></span></td></tr> <tr><td>最慢:</td><td><span id=spanWorst></span></td></tr> <tr><td>平均:</td><td><span id=spanAv></span></td></tr> <tr><td>最好平均:</td><td><span id=spanBestAv></span></td></tr> </table> </body> </html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行
]
教程首页
更多教程