gpt4 book ai didi

javascript - Onclick 某个功能不起作用

转载 作者:行者123 更新时间:2023-12-01 02:53:49 24 4
gpt4 key购买 nike

我正在创建一个带有按钮的在线测验,我的问题是 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

关于javascript - Onclick 某个功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46834009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com