?? 10-8.htm
字號:
<script language="JavaScript">
var Total_Question = 4 <!--題目數量設定-->
var msg = "" <!--用來存儲成績報告的內容-->
var Solution = new Array(Total_Question) <!--此數組用來存儲題目的正確答案-->
Solution[0] = "TCP/IP"
Solution[1] = "集線器"
Solution[2] = "SUN"
Solution[3] = "Microsoft"
function GetSelectedButton(ButtonGroup) <!--此函數用來判斷答題的對錯-->
{
for (var x=0; x < ButtonGroup.length; x++) <!--如果選中某個答案則將此答案的序號返回-->
if (ButtonGroup[x].checked) return x
return 0 <!--如果沒有選中的答案則返回0-->
}
function ReportScore(correct) <!--此函數用來報告成績-->
{
var SecWin =
window.open("","scorewin","scrollbars,width=300,height=220") <!--打開一個帶滾動條的新窗口,寬為300,高為220-->
var MustHave1 = "<HTML><HEAD><TITLE>測驗成績報告</TITLE></HEAD><BODY>" <!--網頁標題-->
var Percent = "<H2>測驗成績 : "+Math.round(correct/Total_Question*100) <!--計算測試成績-->
+ "</H2><HR>"
lastscore=Math.round(correct/Total_Question*100)
if (lastscore == "100"){ <!--如果成績為100分,則加上恭喜的信息-->
msg = MustHave1 +Percent + "<font color='red'>恭喜,全部答對了!</font><p>" + msg + "<input type='button' value='關閉' onclick=javascript:window.close()></BODY></HTML>"}
else { <!--否則,在給出成績的同時,給出答錯了的題的正確答案-->
msg = MustHave1 +Percent + "<font color='red'>正確答案:</font><p>" + msg + "<input type='button' value='close' onclick=javascript:window.close()></BODY></HTML>"
} <!--上面兩種情況都會有一個可以關閉此窗口的按鈕-->
SecWin.document.write(msg) <!--顯示上述信息-->
msg = "" <!--清空msg-->
}
function Grade()
{
var correct = 0 <!--初始化變量,分別表示正確的答題數和錯誤的答題數-->
var wrong = 0
for (number=0; number < Total_Question; number++) <!--number指問題的個數,for循環相當于批閱整個試卷-->
{
var form = document.forms[number] <!--代表某個問題-->
var i = GetSelectedButton(form.q1) <!--調用GetSelectedButton函數判斷對錯-->
if (form.q1[i].value == "1") <!--若返回值為1,則說明答對本題,correct加1-->
{ correct++ }
else
{ wrong++ <!--否則本題答錯,wrong加1-->
msg += "Question "+(number+1)+"." <!--將本題的正確答案賦給msg-->
+Solution[number]+"<BR>"
}
}
ReportScore(correct) <!--調用ReportScore函數-->
}
</script>
<body>
<table width="75%" border="0" align="center">
<tr>
<td>
<form>
回答以下問題:<p>
(1)Internet上使用的網絡協議是:__________
<br>
<input type="radio" name="q1" value="0" checked>X.25
<input type="radio" name="q1" value="1">TCP/IP
<input type="radio" name="q1" value="0">NetBEUI
<br><br> </form>
<form>
(2)HUB是指:__________
<br>
<input type="radio" name="q1" value="0" checked>網橋
<input type="radio" name="q1" value="1">集線器
<input type="radio" name="q1" value="0">網關
<input type="radio" name="q1" value="0">路由器
<br><Br> </form>
<form>
(3)JAVA是哪個公司的產品:__________
<br>
<input type="radio" name="q1" value="0" checked>Novell
<input type="radio" name="q1" value="0">Microsoft
<input type="radio" name="q1" value="1">SUN
<br><Br> </form>
<form>
(4)IIS(Internet Information Server)是哪個公司的產品:__________
<br>
<input type="radio" name="q1" value="0" checked>Novell
<input type="radio" name="q1" value="1">Microsoft
<input type="radio" name="q1" value="0">Netscape
<br><Br> </form>
<form>
<div align="center">
<input type="button" name="Submit" value="看看成績"
onClick="Grade()" class="pt9">
</div>
</form>
</td>
</tr>
</table>
<!--本案例實現了簡單的網絡測試功能-->
<!--主要是通過調用Grade函數來實現的-->
<!--當某個答案被選中時,答案的屬性會變為checked,從而可以判斷正確與否-->
<!--然后用reportscore函數來計算成績,給出報告-->
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -