需要将每个Q中用javascript编写的测验分成1页而不是单页上的所有Q.

时间:2016-03-04 05:59:10

标签: javascript scorm scorm1.2

我目前在一个用javascript编写的页面上进行测验。我需要重写/修改/拆分此代码,以便每个问题都显示在自己的页面上。

我使用了一个名为eXeLearning的工具来构建测验。这是将在LMS上托管的SCORM项目的一部分。我只是不确定如何解决这个问题。我对HTML和CSS很好,我知道一点PHP,但不是javascript。这是有问题的脚本,如果需要,我也可以发布整个代码页:

<script type="text/javascript">
<!-- //<![CDATA[
var numQuestions = 10;
var rawScore = 0;
var actualScore = 0;
var question0;
var question1;
var question2;
var question3;
var question4;
var question5;
var question6;
var question7;
var question8;
var question9;
var key0 = 0;
var key1 = 1;
var key2 = 0;
var key3 = 0;
var key4 = 1;
var key5 = 0;
var key6 = 0;
var key7 = 1;
var key8 = 0;
var key9 = 1;
function getAnswer()
    {
        scorm.SetInteractionValue("cmi.interactions.0.id","key0b0");
        scorm.SetInteractionValue("cmi.interactions.0.type","choice");
        scorm.SetInteractionValue("cmi.interactions.0.correct_responses.0.pattern",
                      "0");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key0b0[i].checked)
           {
              question0 = document.getElementById("quizForm0").key0b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.0.student_response",question0);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.1.id","key1b0");
        scorm.SetInteractionValue("cmi.interactions.1.type","choice");
        scorm.SetInteractionValue("cmi.interactions.1.correct_responses.0.pattern",
                      "1");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key1b0[i].checked)
           {
              question1 = document.getElementById("quizForm0").key1b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.1.student_response",question1);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.2.id","key2b0");
        scorm.SetInteractionValue("cmi.interactions.2.type","choice");
        scorm.SetInteractionValue("cmi.interactions.2.correct_responses.0.pattern",
                      "0");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key2b0[i].checked)
           {
              question2 = document.getElementById("quizForm0").key2b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.2.student_response",question2);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.3.id","key3b0");
        scorm.SetInteractionValue("cmi.interactions.3.type","choice");
        scorm.SetInteractionValue("cmi.interactions.3.correct_responses.0.pattern",
                      "0");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key3b0[i].checked)
           {
              question3 = document.getElementById("quizForm0").key3b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.3.student_response",question3);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.4.id","key4b0");
        scorm.SetInteractionValue("cmi.interactions.4.type","choice");
        scorm.SetInteractionValue("cmi.interactions.4.correct_responses.0.pattern",
                      "1");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key4b0[i].checked)
           {
              question4 = document.getElementById("quizForm0").key4b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.4.student_response",question4);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.5.id","key5b0");
        scorm.SetInteractionValue("cmi.interactions.5.type","choice");
        scorm.SetInteractionValue("cmi.interactions.5.correct_responses.0.pattern",
                      "0");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key5b0[i].checked)
           {
              question5 = document.getElementById("quizForm0").key5b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.5.student_response",question5);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.6.id","key6b0");
        scorm.SetInteractionValue("cmi.interactions.6.type","choice");
        scorm.SetInteractionValue("cmi.interactions.6.correct_responses.0.pattern",
                      "0");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key6b0[i].checked)
           {
              question6 = document.getElementById("quizForm0").key6b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.6.student_response",question6);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.7.id","key7b0");
        scorm.SetInteractionValue("cmi.interactions.7.type","choice");
        scorm.SetInteractionValue("cmi.interactions.7.correct_responses.0.pattern",
                      "1");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key7b0[i].checked)
           {
              question7 = document.getElementById("quizForm0").key7b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.7.student_response",question7);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.8.id","key8b0");
        scorm.SetInteractionValue("cmi.interactions.8.type","choice");
        scorm.SetInteractionValue("cmi.interactions.8.correct_responses.0.pattern",
                      "0");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key8b0[i].checked)
           {
              question8 = document.getElementById("quizForm0").key8b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.8.student_response",question8);
              break;
           }
        }

        scorm.SetInteractionValue("cmi.interactions.9.id","key9b0");
        scorm.SetInteractionValue("cmi.interactions.9.type","choice");
        scorm.SetInteractionValue("cmi.interactions.9.correct_responses.0.pattern",
                      "1");

        for (var i=0; i < 2; i++)
        {
           if (document.getElementById("quizForm0").key9b0[i].checked)
           {
              question9 = document.getElementById("quizForm0").key9b0[i].value;
              scorm.SetInteractionValue("cmi.interactions.9.student_response",question9);
              break;
           }
        }
       }
    function calcRawScore(){

        if (question0 == key0)
        {
           scorm.SetInteractionValue("cmi.interactions.0.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.0.result","wrong");
        }
        if (question1 == key1)
        {
           scorm.SetInteractionValue("cmi.interactions.1.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.1.result","wrong");
        }
        if (question2 == key2)
        {
           scorm.SetInteractionValue("cmi.interactions.2.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.2.result","wrong");
        }
        if (question3 == key3)
        {
           scorm.SetInteractionValue("cmi.interactions.3.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.3.result","wrong");
        }
        if (question4 == key4)
        {
           scorm.SetInteractionValue("cmi.interactions.4.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.4.result","wrong");
        }
        if (question5 == key5)
        {
           scorm.SetInteractionValue("cmi.interactions.5.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.5.result","wrong");
        }
        if (question6 == key6)
        {
           scorm.SetInteractionValue("cmi.interactions.6.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.6.result","wrong");
        }
        if (question7 == key7)
        {
           scorm.SetInteractionValue("cmi.interactions.7.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.7.result","wrong");
        }
        if (question8 == key8)
        {
           scorm.SetInteractionValue("cmi.interactions.8.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.8.result","wrong");
        }
        if (question9 == key9)
        {
           scorm.SetInteractionValue("cmi.interactions.9.result","correct");
           rawScore++;
        }
        else
        {
           scorm.SetInteractionValue("cmi.interactions.9.result","wrong");
        }
    }

    function calcScore2()
    {
       computeTime();  // the student has stopped here.

       document.getElementById("quizForm0").submitB.disabled = true;

       getAnswer();

       calcRawScore();

       actualScore = Math.round(rawScore / numQuestions * 100);
    alert("Your score is " + actualScore + "%")  

       scorm.SetScoreRaw(actualScore+"" );
       scorm.SetScoreMax("100");

       var mode = scorm.GetMode();

           if ( mode != "review"  &&  mode != "browse" ){
             if ( actualScore < 80 )
             {
               scorm.SetCompletionStatus("incomplete");
               scorm.SetSuccessStatus("failed");
             }
             else
             {
               scorm.SetCompletionStatus("completed");
               scorm.SetSuccessStatus("passed");
             }

             scorm.SetExit("");
             }

     exitPageStatus = true;


     scorm.save();

     scorm.quit();

    }
//]]> -->
</script>

1 个答案:

答案 0 :(得分:1)

这是一个非常广泛的问题,你肯定需要学习JavaScript(或聘请某人)才能解决这个问题。我还建议学习JQuery,特别是如果你选择下面的选项1。有很多网站会教你。

就您可采取的一般方法而言,您有两种选择:

  1. 随着学习者的进展,将所有内容保存在一个页面上并显示/隐藏测验问题。

  2. 将问题放入框架并将数据传回父框架。

  3. 我自己会使用选项1,因为现在帧很老式。

    选择一种方法,花点时间学习JavaScript和JQuery,然后回过头来讨论有关实施所选方法的问题的更具体问题。