簡體   English   中英

Onclick到功能不起作用

[英]Onclick to a function doesn't work

我創建了一個帶有按鈕的在線測驗,我的問題是onclick按鈕並沒有真正實現我希望的效果,我是javascript的初學者,所以我希望人們能給我解決方案或替代建議以使其正常運行;

這是我的代碼

<html>
<head>
<title> </title>
</head>
<body>

<div id="qholder"> </div>
<button name="choices" onclick="CheckAnswer('A')" > <p id="choice1"> </p> </button>

<button name="choices" onclick="CheckAnswer('B')" > <p id="choice2"> </p> </button>

<button name="choices" onclick="CheckAnswer('C')" > <p id="choice3"> </p> </button>

<button name="choices" onclick="CheckAnswer('D')" > <p id="choice4"> </p> </button>

<script>

var qpos = 0;
var correctans=0;
var answer=0;


var Quiz = [
    ["What team was the first TI Champion?", "Invictus Gaming", "Team Liquid", "Natus Vincere", "Orange E-Sports", 'C'],
    ["Who was the captain of the First TI Champion Team?", "Puppey", "Artstyle", "Kuroky", "xiao8", 'B'],
    ["Where does Natus Vincere Operate?", "USA", "Moscow", "Philippines", "Ukraine", 'D'],
    ["Who played Midlane for Natus Vincere?", "Miracle", "Suma1l", "Dendi", "Maybe", 'C'],
    ["How many TI grandfinals did Team Natus Vincere played in?", "3", "2", "1", "4", '1'],
    ["Who replaced LightofHeaven after leaving Natus Vincere?", "General", "Sonneiko", "rodger", "Funn1k", 'D'],
    ["Who defeated Na'Vi in the TI3 Grand Finals?", "Team Liquid", "Cloud 8", "Evil Geniuses", "Team Alliance", 'D'],
    ["Who is the current captain of Team Na'Vi?", "Pajkatt", "Cr1t", "Sonneiko", "Fly", 'C'],
    ["Who is the owner of Na'Vi?", "Gaben", "CyborgMatt", "ODpixel", "zer0gravity", 'D'],
    ["When was Team Natus Vincere Founded?", "July 1996", "December 2009", "November 2012", "March 2017", 'B']
];

function startquiz(){   
    getQuestions(); 
};  

function getQuestions() {

        document.getElementById("qholder").innerHTML = Quiz[qpos][0];
        document.getElementById("choice1").innerHTML = Quiz[qpos][1];
        document.getElementById("choice2").innerHTML = Quiz[qpos][2];
        document.getElementById("choice3").innerHTML = Quiz[qpos][3];
        document.getElementById("choice4").innerHTML = Quiz[qpos][4];

        };  


function CheckAnswer (answer){
    if(Quiz[qpos][5] == answer) {
      correctans + 1; 
    };
  getnextQuestion();    
};


function getnextQuestion() {
    qpos + 1;
    getQuestions();
};

startquiz();

</script>
</body>
</html>

請幫忙,我已經花了好幾個小時試圖找出答案,我對問題,選擇和答案使用了多維數組,希望onclick按鈕可以在檢查點擊的答案是否正確時繼續下一個問題

qpos + 1

至少需要為qpos++qpos = qpos + 1

function CheckAnswer (answer){
    if(Quiz[qpos][5] == answer) {
        correctans++; 
    };
    getnextQuestion();  
};


function getnextQuestion() {
    qpos++;
    getQuestions();
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM