如何通过单击滚动对象数组中的问题?
How to scroll through questions in an object array by clicking?
let questions = {
question1: "This is the first question",
question2: "And this is the second",
question3: "Another one"
}
for(const [key, value] of Object.entries(questions)){
document.addEventListener("click", () => document.write(value));
}
据我了解,您希望在用户单击 window 上的某处时按顺序显示问题。
let questions = {
question1: "This is the first question",
question2: "And this is the second",
question3: "Another one"
}
const questionsArray = Object.values(questions);
document.addEventListener("click", () => {
document.write(questionsArray.shift());
})
let questions = {
question1: "This is the first question",
question2: "And this is the second",
question3: "Another one"
}
for(const [key, value] of Object.entries(questions)){
document.addEventListener("click", () => document.write(value));
}
据我了解,您希望在用户单击 window 上的某处时按顺序显示问题。
let questions = {
question1: "This is the first question",
question2: "And this is the second",
question3: "Another one"
}
const questionsArray = Object.values(questions);
document.addEventListener("click", () => {
document.write(questionsArray.shift());
})