| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1344 人关注过本帖
标题:javascript制作在线试题的问题(求助)
只看楼主 加入收藏
jwy__110
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-27
收藏
 问题点数:0 回复次数:2 
javascript制作在线试题的问题(求助)
做一份试题,做完后提交显示出新的页面,得到分数和错误试题的答案,但时我提交了以后就会出现空白页,试了很久都没解决,问题好像出在calculateScore的函数里,但不知道怎么错了,哪位大哥帮忙看看,小弟不胜感激,代码如下:
<html>
<head>
<script type = "text/javascript">
var num_MC = 6;
var num_TF = 4 ;//number of question

var solution_MC = new Array(num_MC);
solution_MC[0] = "18";
solution_MC[1] = "27";
solution_MC[2] = "11";
solution_MC[3] = "1.25";
solution_MC[4] = "1.6";
solution_MC[5] = "-5";

var solution_TF = new Array(num_TF);
solution_TF[0] = "False";
solution_TF[1] = "True";
solution_TF[2] = "False";
solution_TF[3] = "False";

var marks = 0;

function CalculateScore()
{        
    var number;
    var number1;
    var result_MC = "";
    var result_TF = "";
    
    for (number=0; number < num_MC; number++)
    {
        if (document.MC.q1[num_MC].value == "1")
        {
          marks+=12;
         }
        
        else
        {
          result_MC += "Question "+(number+1) + ": " + solution_MC[number] + "<BR>";
        }
    }
    
    for (number1=0; number1 < num_TF; number1++)
    {
        if (document.TF.q2[num_TF].value == "1")
        {
          marks+=7;
        }
        else
        {
          result_TF += "Question "+(number1+7) + ":" + solution_TF[number1] + "<BR>";
         }
     }
}

var ScoreWin;

function ScoreWinWindow()
{
    ScoreWin = window.open("","answers","resizable=no, toolbar=no, menubar=no, status=no, location=no, scrollBars=yes");
            
    CalculateScore();
    
    if(marks == "100")
    {
        ScoreWin.document.write("<font color = 'red'> Congralation, the answers are all right!!");
    }
    else
    {
        ScoreWin.document.write("<font color='red'>Correct Answers:</font><p>" + result_MC + result_TF);
    }
    
    ScoreWin.document.write( "Your Test Result is " + marks + "/100");
}
</script>
</head>

<body>
<tr>
<td>
<form><center>Online Quiz - Math Test</center><p></form>
Mutiple Choice  (6*12)<HR>
<form id = "MC" action = "JavaScript:CalculateScore()">
<form>
(1) 2 * 9 = ____
<br>
<input type="radio" name="q1" value="0">17
<input type="radio" name="q1" value="1">18
<input type="radio" name="q1" value="0">27
<input type="radio" name="q1" value="0">19
<br><br>
</form>
<form>
(2) 3 * 7 = ____
<br>
<input type="radio" name="q1" value="0">22
<input type="radio" name="q1" value="1">21
<input type="radio" name="q1" value="0">14
<input type="radio" name="q1" value="0">20
<br><br>
</form>
<form>
(3) 4 + 7 = ____
<br>
<input type="radio" name="q1" value="0">14
<input type="radio" name="q1" value="0">10
<input type="radio" name="q1" value="1">11
<input type="radio" name="q1" value="0">13
<br><br>
</form>
<form>
(4) 5 / 4 = ____
<br>
<input type="radio" name="q1" value="0">1
<input type="radio" name="q1" value="1">1.25
<input type="radio" name="q1" value="0">2
<input type="radio" name="q1" value="0">9
<br><br>
</form>
<form>
(5) 8 / 5 = ____
<br>
<input type="radio" name="q1" value="0">1
<input type="radio" name="q1" value="1">1.6
<input type="radio" name="q1" value="0">2
<input type="radio" name="q1" value="0">4
<br><br>
</form>
<form>
(6) 9 - 14 = ____
<br>
<input type="radio" name="q1" value="0">5
<input type="radio" name="q1" value="0">4
<input type="radio" name="q1" value="0">0
<input type="radio" name="q1" value="1">-5
<br><br>
</form>
</form>

True or False  (4*7)<HR>

<form id = "TF" action = "JavaScript:CalculateScore()">
<form>
(7) 5 - 17 = 12
<br>
<input type="radio" name="q2" value="0" >True
<input type="radio" name="q2" value="1" >False
<br><br>
</form>
<form>
(8) 15 * 5 = 75
<br>
<input type="radio" name="q2" value="1" >True
<input type="radio" name="q2" value="0" >False
<br><br>
</form>
<form>
(9) 25 - 78 = 53
<br>
<input type="radio" name="q2" value="0">True
<input type="radio" name="q2" value="1">False
<br><br>
</form>
<form>
(10) 14 / 3 = 4
<br>
<input type="radio" name="q2" value="0" >True
<input type="radio" name="q2" value="1" >False
<br><br>
</form>
</form>

<form>
<div align="center">
<input type="button" name="Submit" value="Submit" onClick="ScoreWinWindow()">
</div>
</form>
</td>
</tr>
</body>
</html>
搜索更多相关主题的帖子: 试题 javascript 制作 在线 
2008-10-27 15:11
jwy110
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-11-4
收藏
得分:0 
我改了一下,页面可以显示,但是无法计算了,无论错和对,都会显示所有的答案,为什么?
<html>
<head>
<script type = "text/javascript">
var numQuiz = 10;
var solution = new Array(numQuiz);
solution[0] = "18";
solution[1] = "27";
solution[2] = "11";
solution[3] = "1.25";
solution[4] = "1.6";
solution[5] = "-5";
solution[6] = "False";
solution[7] = "True";
solution[8] = "False";
solution[9] = "False";

var marks =0;
var ScoreWin;
var result = "";

function CalculateScore()
{    
    if     (document.quiz.q1.value=="1"){ marks+=12;}
    else {result+="Question 1: " + solution[0] +"<br>"}
    
    if     (document.quiz.q2.value=="1"){marks+=12;}
    else {result+="Question 2: " + solution[1] +"<br>"}
    
    if     (document.quiz.q3.value=="1"){marks+=12;}
    else {result+="Question 3: " + solution[2] +"<br>"}
       
    if     (document.quiz.q4.value=="1"){marks+=12;}
    else {result+="Question 4: " + solution[3] +"<br>"}
      
    if     (document.quiz.q5.value=="1"){marks+=12;}  
    else {result+="Question 5: " + solution[4] +"<br>"}
    
    if     (document.quiz.q6.value=="1"){marks+=12;}
    else {result+="Question 6: " + solution[5] +"<br>"}
    
    if     (document.quiz.q7.value=="1"){marks+=7;}
    else {result+="Question 7: " + solution[6] +"<br>"}
    
    if     (document.quiz.q8.value=="1"){marks+=7;}
    else {result+="Question 8: " + solution[7] +"<br>"}
    
    if     (document.quiz.q9.value=="1"){marks+=7;}
    else {result+="Question 9: " + solution[8] +"<br>"}
    
    if     (document.quiz.q10.value=="1"){marks+=7;}
    else {result+="Question 10: " + solution[9] +"<br>"}
    
    ScoreWin = window.open("","answers","resizable=no, toolbar=no, menubar=no, status=no, location=no, scrollBars=yes");

                                
    if(marks ==100)
    {
        ScoreWin.document.write("<font color = 'red'> Congralation, the answers are all right!!");
        ScoreWin.document.write( "Your Test Result is " + marks +"<br>");
    }
    else
    {
        ScoreWin.document.write( "Your Test Result is " + marks +"<br>");
        ScoreWin.document.write("Correct Answers"+"<br>" + result);
    }         
}
</script>
</head>

<body>
<tr>
<td>
<form name="quiz">
<center><b>Online Quiz - Math Test</b></center>
<b>Mutiple Choice  (6*12)</b><HR>
(1) 2 * 9 = ____
<br>
<input type="radio" name="q1" value="0" checked>17
<input type="radio" name="q1" value="1">18
<input type="radio" name="q1" value="0">27
<input type="radio" name="q1" value="0">19
<br>
<p>
(2) 3 * 7 = ____
<br>
<input type="radio" name="q2" value="0" checked>22
<input type="radio" name="q2" value="1">21
<input type="radio" name="q2" value="0">14
<input type="radio" name="q2" value="0">20
<br>
<p>
(3) 4 + 7 = ____
<br>
<input type="radio" name="q3" value="0" checked>14
<input type="radio" name="q3" value="0">10
<input type="radio" name="q3" value="1">11
<input type="radio" name="q3" value="0">13
<br>
<p>
(4) 5 / 4 = ____
<br>
<input type="radio" name="q4" value="0" checked>1
<input type="radio" name="q4" value="1">1.25
<input type="radio" name="q4" value="0">2
<input type="radio" name="q4" value="0">9
<br>
<p>
(5) 8 / 5 = ____
<br>
<input type="radio" name="q5" value="0" checked>1
<input type="radio" name="q5" value="1">1.6
<input type="radio" name="q5" value="0">2
<input type="radio" name="q5" value="0">4
<br>
<p>
(6) 9 - 14 = ____
<br>
<input type="radio" name="q6" value="0" checked>5
<input type="radio" name="q6" value="0">4
<input type="radio" name="q6" value="0">0
<input type="radio" name="q6" value="1">-5
<br>
<p>

<b>True or False  (4*7)</b><HR>
(7) 5 - 17 = 12
<br>
<input type="radio" name="q7" value="0" checked>True
<input type="radio" name="q7" value="1" >False
<br>
<p>
(8) 15 * 5 = 75
<br>
<input type="radio" name="q8" value="1" checked>True
<input type="radio" name="q8" value="0" >False
<br>
<p>

(9) 25 - 78 = 53
<br>
<input type="radio" name="q9" value="0" checked>True
<input type="radio" name="q9" value="1">False
<br>
<p>

(10) 14 / 3 = 4
<br>
<input type="radio" name="q10" value="0" checked>True
<input type="radio" name="q10" value="1" >False
<br>
<p>

<div align="center">
<input type="button" name="Submit" value="Submit" onClick="CalculateScore()">
</div>
</form>
</td>
</tr>
</body>
</html>
2008-10-29 13:38
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
程序代码:
<html>
<head>
<script type = "text/javascript">
var num_MC = 6;
var num_TF = 4 ;//number of question

var solution_MC = new Array(num_MC);
solution_MC[0] = "18";
solution_MC[1] = "21";
solution_MC[2] = "11";
solution_MC[3] = "1.25";
solution_MC[4] = "1.6";
solution_MC[5] = "-5";

var solution_TF = new Array(num_TF);
solution_TF[0] = "False";
solution_TF[1] = "True";
solution_TF[2] = "False";
solution_TF[3] = "False";

var marks = 0;


var result_MC = "";
    var result_TF = "";
function CalculateScore()
{        
    var number;
    var number1;
    var str;
    var i;
    var nm,nm1;
    for (number=1; number <=num_MC; number++)
    {
      
      for(i=0;i<4;i++){
          str="document.MC.q"+number+"["+i+"].checked";
          
          
          if(eval(str))
          {
            str="document.MC.q"+number+"["+i+"].value";
            
            if ( eval(str)== "1")
            {
         
             marks+=12;
             
            }
            else        
            { 
               result_MC += "Question "+(number) + ": " + solution_MC[number-1] + "<BR>";
            }
          }
       }  
       
    }
    
    for (number1=1; number1 <= num_TF; number1++)
    {
        for(i=0;i<2;i++){
          str="document.TF.p"+number1+"["+i+"].checked";
          
          
          if(eval(str))
          {
            str="document.TF.p"+number1+"["+i+"].value";
            
            if ( eval(str)== "1")
            {
         
             marks+=7;
             
            }
            else        
            { 
               result_TF += "Question "+(number1) + ":" + solution_TF[number1-1] + "<BR>";
            }
          }
       }

        
     }
}

var ScoreWin;

function ScoreWinWindow()
{
    ScoreWin = window.open("","answers","resizable=no, toolbar=no, menubar=no, status=no, location=no, scrollBars=yes");
            
    CalculateScore();
    
    if(marks == "100")
    {
        ScoreWin.document.write("<font color = 'red'> Congralation, the answers are all right!!");
    }
    else 
    {
        ScoreWin.document.write("<font color='red'>Correct Answers:</font><p>" + result_MC + result_TF);
    } 
    
    ScoreWin.document.write( "Your Test Result is " + marks + "/100");
}
</script>
</head>

<body>
<tr>
<td>
<form><center>Online Quiz - Math Test</center><p></form>
Mutiple Choice  (6*12)<HR>
<form name = "MC" action = "JavaScript:CalculateScore()">

(1) 2 * 9 = ____
<br>
<input type="radio" name="q1" value="0">17
<input type="radio" name="q1" value="1">18
<input type="radio" name="q1" value="0">27
<input type="radio" name="q1" value="0">19
<br><br> 


(2) 3 * 7 = ____
<br>
<input type="radio" name="q2" value="0">22
<input type="radio" name="q2" value="1">21
<input type="radio" name="q2" value="0">14
<input type="radio" name="q2" value="0">20
<br><br> 
(3) 4 + 7 = ____
<br>
<input type="radio" name="q3" value="0">14
<input type="radio" name="q3" value="0">10
<input type="radio" name="q3" value="1">11
<input type="radio" name="q3" value="0">13
<br><br>
(4) 5 / 4 = ____
<br>
<input type="radio" name="q4" value="0">1
<input type="radio" name="q4" value="1">1.25
<input type="radio" name="q4" value="0">2
<input type="radio" name="q4" value="0">9
<br><br> 
(5) 8 / 5 = ____
<br>
<input type="radio" name="q5" value="0">1
<input type="radio" name="q5" value="1">1.6
<input type="radio" name="q5" value="0">2
<input type="radio" name="q5" value="0">4
<br><br> 
(6) 9 - 14 = ____
<br>
<input type="radio" name="q6" value="0">5
<input type="radio" name="q6" value="0">4
<input type="radio" name="q6" value="0">0
<input type="radio" name="q6" value="1">-5
<br><br> 
</form>

True or False  (4*7)<HR>

<form name = "TF" action = "JavaScript:CalculateScore()"> 

(7) 5 - 17 = 12
<br>
<input type="radio" name="p1" value="0" >True
<input type="radio" name="p1" value="1" >False
<br><br>
(8) 15 * 5 = 75
<br>
<input type="radio" name="p2" value="1" >True
<input type="radio" name="p2" value="0" >False
<br><br> 
(9) 25 - 78 = 53
<br>
<input type="radio" name="p3" value="0">True
<input type="radio" name="p3" value="1">False
<br><br> 
(10) 14 / 3 = 4
<br>
<input type="radio" name="p4" value="0" >True
<input type="radio" name="p4" value="1" >False
<br><br> 
</form>

<form>
<div align="center">
<input type="button" name="Submit" value="Submit" onClick="ScoreWinWindow()">
</div>
</form>
</td>
</tr>
</body>
</html>

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2008-11-05 17:05
快速回复:javascript制作在线试题的问题(求助)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035471 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved