香烟 发表于 2007-4-27 11:17:28

***测试搜索***给出试题,完成后跳窗显示成线和答案

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
要完成此效果需要两个步骤

第一步:把如下代码加入到<head>区域中

<script language="javascript">



var total_question = 4      // 修改这里与题目数量一致



var msg = ""



// 正确答案

var solution = new array(total_question)

solution = "tcp/ip"

solution = "集线器"

solution = "sun"

solution = "microsoft"

//



function getselectedbutton(buttongroup)

{

for (var x=0; x < buttongroup.length; x++)

    if (buttongroup.checked) return x

return 0

}



function reportscore(correct)

{

var secwin =

      window.open("","scorewin","scrollbars,width=300,height=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"){

msg = musthave1 +percent + "<font color='red'>恭喜,全部答对了!</font><p>" + msg+ "<input type='button' value='close' 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++)

    {

      var form = document.forms      // question #

      var i = getselectedbutton(form.q1)

      if (form.q1.value == "1")

   { correct++ }

    else

   { wrong++

       msg += "question "+(number+1)+"."

          +solution+"<br>"

   }

    }

    reportscore(correct)



}





</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>
      










--- ------- --------- - - ------ -----------

ht tp://www.huoyue.com .cn 活跃网,活跃人群的论坛,访问 活跃网, 将给您带来意想不到的收获,还可以免费为您开论坛,让您免费拥有与朋友、网友交流的论 坛。你是年轻人吗 ?你活跃你就上!
页: [1]
查看完整版本: ***测试搜索***给出试题,完成后跳窗显示成线和答案