简体   繁体   English

每次按下下一个问题按钮时,我都想将其更改为数组中写入的内容

[英]I want to change this to what is written in the array every time a next question button is pushed

So I have 4 areas in the HTML: Questions, Notes, Button1, Button2.所以我在 HTML 中有 4 个区域:问题、注释、Button1、Button2。 I have an Object with values for each in their own arrays:我有一个对象,每个对象在自己的数组中都有值:

var list = {
    1: ['This is question 1', 'These are notes 1', 'this is answer 1A', 'this is answer 1B'],
    2: ['This is question 2', 'These are notes 2', 'this is answer 2A', 'this is answer 2B']

}; 

When I click the next question button, I want the values to change to the next line of the object Here is my function:当我单击下一个问题按钮时,我希望将值更改为对象的下一行 这是我的函数:

var i = 0;

function nextQuestion() {
    i += 1;    
    document.getElementById('question').innerHTML = list.i[0];
    document.getElementById('notes').innerHTML = list.i[1];
    document.getElementById('btn1').value = list.i[2];
    document.getElementById('btn2').value = list.i[3]; 
}

I know that I'm close, but I'm a beginner and don't know what I need to do here.我知道我很接近,但我是初学者,不知道我需要在这里做什么。

MAYBE A FOR LOOP???可能是一个 FOR 循环???

Thanks谢谢

Change list.i[0];更改list.i[0]; to list[i][0]; list[i][0]; and it should work.它应该工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有 5 个问题。 当我单击下一个按钮时,我希望下一个问题显示在 h2 元素中 - I have an array of 5 questions. When I click the next button, I want the next question to be shown in the h2 element 你能指导我一个问题吗,我每次按下按钮时都会尝试更改颜色 - Can you guide me with a question, I am trying to change the color every time I press a button 我希望每次单击按钮时都可以将每张图片更改为显示在屏幕上的同一位置 - I want to be able to change each picture to appear in the same place on the screen every time i click a button 我想创建一个计数器,每次单击 javascript 中的按钮时都会更改 - i want to create a counter which change every time i click on the button in javascript 每次用户单击按钮时,我都需要Javascript数组中的下一个值 - Every time user clicks on the button I need the next value from the array in Javascript 如何使按钮在每次按下时创建不同的文本? - How to make a button create a different text every time it is pushed? 我想用数组中的下一个值更改 state 的值 - I want to change the value of the state with the next values from an array 我正在创建一个包含 5 个随机问题的测验(从一个包含 20 个问题的数组中)。 我想为每个可能的问题分配一张图片 - I'm creating a quiz with 5 random questions (out of an array with 20). I want to assign a picture to every possible question 我想在每次调用函数时打印下一天的名称 - I want to print the name of Next Day every time I call my function 每次单击按钮时如何在数组中显示3个项目 - How to show 3 items in an array every time I click on button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM