<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<style type="text/css">
body { padding:0; margin:0; font-family:Georgia, "Times New Roman", Times, serif; background:#FFC;}
#wrapper { width:960px; margin:0 auto;}
#question {
margin:20px 0; font-size:20px;}
#answers {font-size:16px; }
#result { display:none;}
</style>
</head>

<body>
<div id="wrapper">
<h1>HTML测试题
</h1>
<div id="test">
<p id="info">本测试共<span class="total">0</span>题,当前第<span class="num">0</span>题,每题20分。</p>
<p id="question">题目</p>
<p id="answers">选项</p>
<button type="button" id="prev" style="display:none;">上一题</button>
<button type="button" id="next">下一题</button>
</div>
<div id="result">
<h2>你的测试成绩是<span id="score">0</span>分</h2>
<button type="button" id="retry">再试一次</button>
</div>
</div>
</body>
<script>
$(document).ready(function() {
var questions = [{question:"Html是指超文本连接标识语言。它主要告诉浏览器什么?",answers:["什么是网页","有哪些浏览资源","资源存放的位置","网址是什么"],correctAnswer:2},{question:"下列程序不能编辑Html文件的是?",answers:["记事本","写字板","word","计算器"],correctAnswer:2},{question:"网页文件的扩展名可以是?",answers:[".htm",".bat",".doc",".rar"],correctAnswer:0}];
var totalQues = questions.length;
var currQues = 0;
var userAnswers = [];
var score = 0;
showQuestion(currQues,questions);
$("#next").on("click",function(){
switch(currQues) {
case 0 :
currQues = 1;
$("#prev").show();
showQuestion(currQues,questions);
break;
case (totalQues - 2) :
currQues += 1;
$("#next").text("查看测试结果");
showQuestion(currQues,questions);
break;
case totalQues - 1 :
showResult();
break;
default :
currQues += 1;
showQuestion(currQues,questions);
}


});
$("#prev").on("click",function(){
switch(currQues) {
case 1 :
currQues = 0;
$("#prev").hide();
showQuestion(currQues,questions);
break;
case (totalQues - 1) :
currQues -= 1;
$("#next").text("下一题");
showQuestion(currQues,questions);
break;
default :
currQues -= 1;
showQuestion(currQues,questions);
}
});

$("#answers").on("click",":radio",function(){
userAnswers[currQues] = $(this).val();
});

$("#retry").on("click",function(){
window.location.reload();
});

function showQuestion(num,questions) {
var total = questions.length;
var atext = "";
$("#info").find(".total").text(total);
$("#info").find(".num").text(num + 1);
$("#question").text(questions[num].question);
if(userAnswers[num]) {
for(var i=0;i<questions[num].answers.length;i++){
if(userAnswers[num] == i) {
atext += '<input name="answers" type="radio" checked="checked" value="'+ i +'">' + questions[num].answers[i];
} else {
atext += '<input name="answers" type="radio" value="'+ i +'">' + questions[num].answers[i];
}
}
} else {
for(var i=0;i<questions[num].answers.length;i++){
atext += '<input name="answers" type="radio" value="'+ i +'">' + questions[num].answers[i];
}
}
$("#answers").html(atext);
}

function showResult() {
for(var i in questions) {
if(userAnswers[i] == questions[i].correctAnswer) {
score += 20;
}
}
$("#score").text(score);
$("#test").hide();
$("#result").show();
}
});
</script>
</html>

更多相关文章

  1. Python PyV8安装测试(Win7)
  2. 如何让django芹菜写入测试数据库进行功能测试?
  3. python 之 自制测试框架
  4. Python测试函数和类 笨方法学习Python
  5. Python 3.4 AssertEqual()在Django单元测试中使用时的未预测行为
  6. Django:测试成功加载静态文件
  7. Appium基于Python APP自动化测试框架
  8. 初学者的Selenium自动化测试指南,基于Python(五)——常用键盘事件
  9. 基于Python的XSS测试工具XSStrike使用方法

随机推荐

  1. 在两台服务器上有效地在两个Django应用程
  2. python 核心编程第六章课后题自己做的答
  3. 使用python脚本配置zabbix发送报警邮件
  4. Python PyV8安装测试(Win7)
  5. Python引起的混乱解决之道——感悟
  6. 使用Python操作MongoDB
  7. Python第十天 print >> f,和fd.write()的
  8. 如何用位于括号外的逗号分隔字符串?
  9. 数组与矩阵---需要排序的最短子数组长度
  10. 如何为Google Cloud Endpoints方法生成py