无法在javascript中编写循环,无法将数据上传到mysql

时间:2017-03-05 20:28:58

标签: javascript php mysql

我想为学生创建一个在线考试页面。问题意味着加载到javascript中,单击按钮后,答案需要上传到MySQL数据库。

无法找到错误,请帮助我。

<style>
div#test{ border:#000 1px solid; padding:10px 40px 40px 40px; }
</style>
<script>
var res = <?= $r?>;
var no =<?= $n?>;
var pos = 0, test, test_status, question, choice, choices, chA, chB, chC, correct = 0;
var questions = [
                for(var a=0; a<=4; a++){
        [ "<?= $r[1]?>", "<?= $r[5]?>", "<?= $r[6]?>", "<?= $r[7]?>", "<?= $r[8]?>", "<?= $r[9]?>"]
                }
    ];
function _(x){
    return document.getElementById(x);
}
function renderQuestion(){
    test = _("test");
    if(pos >= questions.length){
        test.innerHTML = "<h2>You got "+correct+" of "+questions.length+" questions correct</h2>";
        _("test_status").innerHTML = "Test Completed";
        pos = 0;
        correct = 0;
        return false;
    }
    _("test_status").innerHTML = "Question "+(pos+1)+" of "+questions.length;
    question = questions[pos][1];
    chA = questions[pos][2];
    chB = questions[pos][3];
    chC = questions[pos][4];
    chD = questions[pos][5];
    test.innerHTML = "<h3>"+question+"</h3>";
    test.innerHTML += "<input type='radio' name='choices' value='A'> "+chA+"<br>";
    test.innerHTML += "<input type='radio' name='choices' value='B'> "+chB+"<br>";
    test.innerHTML += "<input type='radio' name='choices' value='C'> "+chC+"<br>";
    test.innerHTML += "<input type='radio' name='choices' value='C'> "+chD+"<br><br>";
    test.innerHTML += "<button onclick='checkAnswer()'>Submit Answer</button>";
}
function checkAnswer(){
    choices = document.getElementsByName("choices");
    for(var i=0; i<choices.length; i++){
        if(choices[i].checked){
            choice = choices[i].value;
        }
    }
    if(choice == questions[pos][4]){
        correct++;
    }
    pos++;
    renderQuestion();
}
window.addEventListener("load", renderQuestion, false);
</script>

0 个答案:

没有答案