javascript - 每次按下下一个问题按钮时,我都想将其更改为数组中写入的内容
问题描述
所以我在 HTML 中有 4 个区域:问题、注释、Button1、Button2。我有一个对象,每个对象都有自己的数组中的值:
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']
};
当我单击下一个问题按钮时,我希望将值更改为对象的下一行这是我的函数:
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];
}
我知道我很接近,但我是一个初学者,不知道我需要在这里做什么。
也许是一个循环???
谢谢
解决方案
更改list.i[0];
为list[i][0];
它应该可以工作。
推荐阅读
- java - 将字符串计算为双精度(后缀符号)
- list - 将 https 请求带入对象
- html - Bootstrap v4 - 使用下拉菜单隐藏/显示折叠
- reactjs - 通过 django rest api 发布大量 JSON 数据
- sql - 在 PostrgeSQL 中使用 Json_array_elements_text() 的 2 种方法
- r - GGPLOT 错误:美学必须是长度 1 或与数据 (1) 相同:x 和 y
- google-apps-script - POST REST API 函数使用带有异常 AD_REQUEST 的 Google 脚本错误
- c - 使用“Free()”命令后程序崩溃 (C)
- php - 如何使用 php yii 将 url 定向到控制器
- php - 如何解析php数组响应