onclick功能不起作用

问题描述:

即时通讯按钮创建一个在线测验,我的问题是,onclick按钮并没有真正做我希望它会,我是一个JavaScript的初学者,所以我希望人们可以给我解决方案或其他建议使其发挥作用;onclick功能不起作用

这里是我的代码

<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继续到下一个问题,而它检查是否点击的答案是正确的

+2

'onclick按钮并不是真的在做我所希望的事情。你希望它会做什么,它现在没有做? –

+1

我希望当你点击它时,它会运行函数CheckAnswer(1)的参数内的值,所以我可以将该值与正确的答案,这是我的Quiz [pos] [5]数组,但它不这样做 –

qpos + 1 

需求,要么是qpos++qpos = qpos + 1起码

+0

哇,谢谢你这么多,这ACTUALLY固定它我知道有没有任何错误与我如何设置我的按钮噢,谢谢你这个固定的一切 对不起,我即时大肆宣传现在因为我卡住了一段时间 –

+1

只是一个专业提示,你可以通过添加控制台记录事物(我确实了解了你的值是否正在改变),或者在浏览器的开发工具中使用了断点。 – maggiekh

+0

正式指出再次感谢 –

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


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

修复它与以前的帖子,你的想法一样谢谢 –