?? 10-3.htm
字號:
<html>
<head>
<title>打字速度測試</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
msg = new Array("Practicing with your typing can greatly help your overall computer skills.",
"A new computer is sold in the US every hour!",
"When do birds migrate from North to South?",
"Perplexing phrases, like this one, are tougher to type.") <!--msg用來存儲測試樣例-->
word = 10
function m() { <!--中級者的測試樣例-->
msg = new Array("Practicing with your typing can greatly help your overall computer skills.",
"A new computer is sold in the US every hour!",
"When do birds migrate from North to South?",
"Perplexing phrases, like this one, are tough to type.")
word = 10
}
function e() { <!--高級者的測試樣例-->
msg = new Array("If you can correctly, and quickly, type this perplexing sentence, you are one superb typist!",
"You are one superb typist if you can correctly, and quickly, type this long phrase.",
"I believe you're a good typist, so I believe you will correctly copy this statement!",
"Because this is not a fairly simple phrase, could you swiftly, and precisely, copy it?")
word = 15
}
function s() { <!--初級者的測試樣例-->
msg = new Array("Computers are the medium of the future.",
"Can you type this phrase rather quickly?",
"Who is the President of the US?",
"I believe that you can type well!")
word = 7
}
function beginIt() { <!--此函數是開始測試時的設置-->
randNum = Math.floor((Math.random() * 10)) % 4 <!--產生一個0-3的隨機整數-->
msgType = msg[randNum] <!--將對應的msg信息賦給msgType-->
day = new Date(); <!--定義一個新的時間日期變量-->
startType = day.getTime(); <!--把當前的時間賦給startType-->
document.theForm.given.value = msgType <!--在given欄中顯示選中的測試樣例-->
document.theForm.typed.focus(); <!--光標顯示在要打字的文本框typed中-->
document.theForm.typed.select();
}
function cheat() { <!--此函數為了防止作弊現象-->
alert("對不起,這里的內容你不能改變!!"); <!--當鼠標點擊given欄范圍內時彈出提示框-->
document.theForm.typed.focus(); <!--光標轉移到typed欄中-->
}
function stopIt() { <!--此函數是測試完成時的操作-->
dayTwo = new Date();
endType = dayTwo.getTime(); <!--把當前的時間賦給endType-->
totalTime = ((endType - startType) / 1000) <!--計算所用時間,以秒作單位-->
spd = Math.round((word/totalTime) * 60) <!--計算打字速度-->
if (document.theForm.typed.value == document.theForm.given.value) { <!--如果輸入字符和給定字符完全相同,則彈出提示框,并給出所用時間和打字速度-->
alert("\n你輸入了 " + word + " 個字符,在 "
+ totalTime + " 秒內, 速度為每分鐘 " + spd + " 個字符!")
}
else {
alert("你輸入有錯,但是你每分鐘輸入 " + spd + " 個字符.") <!--否則給出出錯信息和打字速度-->
}
}
</SCRIPT>
<FORM name="theForm">
<TABLE BORDER=3 CELLSPACING=0 CELLPADDING=0>
<TR>
<TD>你是個...</TD>
<TD align=center><input type=radio name="sme" value="Beginner" onClick="s()" checked>初級者
<input type=radio name="sme" value="Novice" onClick="m()">中級者
<input type=radio name="sme" value="Expert" onClick="e()">高級者</TD>
</TR>
<TR><TD colspan=2><BR>
<center><input type=button value="開始測試" name="start" onClick="beginIt()"></center><P>
<textarea name="given" cols=53 rows=3 wrap=on onFocus="cheat()"></textarea></TD>
</TR>
<TR><TD colspan=2><center><input type=text name="typed" size=45>
<input type=button value="完成" name="stop" onClick="stopIt()"></center></TD>
</TR>
</TABLE></FORM>
<body>
</body>
</html>
<!--本案例實現了測試打字速度的功能-->
<!--測試分為三個難度,用前面的單選框來選擇-->
<!--用beginIt和stopIt函數配合實現檢查錯誤,計算時間和速度并顯示這些信息的功能-->
<!--用cheat函數來防止測試者作弊-->
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -