我做一个简单的数学游戏,想问题的数组传递到哈巴狗。如果用户得到一个正确的问题,我想更新比分,并显示一个新的问题。但是,我不知道我怎么可以通过帕格动态访问和更新网站...
在传递Express中值:
return res.render('play', { questions: questionArray, score: 0});
帕格文件:
p#question #{questions[score].num1} #{questions[score].operation} #{questions[score].num2}
p#score #{score}
input#answer
button.btn.btn-primary(onclick='checkAnswer(questions[score], score)') Enter
当我点击按钮,检查答案,我得到的错误在控制台“的问题不是在HTMLButtonElement.onclick定义”。我检查围绕如何在帕格的onclick使用,但它似乎没有工作。有些人建议JSON.stringify,但它似乎没有工作。
提前致谢!
您可以使用,PUG String Interpolation,喜欢这里;
p#question #{questions[score].num1} #{questions[score].operation} #{questions[score].num2}
p#score #{score}
input#answer
button.btn.btn-primary#check-button Enter
script(type="text/javascript").
document.getElementById('check-button').addEventListener('click', function() {
let score = !{score};
let qScore = !{quesstions[score]}
// put things in "checkAnswer" function here
});
希望这个作品! :)