我有 JS 测验,问题是从数组中随机选择的。我试图用图像(俱乐部徽章)替换每个问题,但保持答案格式不变。这可能吗?如何实现?
当前代码如下:
JavaScript
const questions = [
{
question: `What league do Manchester United play in?`,
answers: [
{text: 'Premier League', correct: true},
{text: 'Championship', correct: false},
{text: 'League One', correct: false},
{text: 'Scottish Premiership', correct: false}
]
},
{
question: 'What league do Millwall play in?',
answers: [
{text: 'Premier League', correct: false},
{text: 'Championship', correct: true},
{text: 'League One', correct: false},
{text: 'Scottish Premiership', correct: false}
]
},
HTML:
<div id="question"><img id="crest" src="assets/images/image1.png"></div>
我已经在 JS 中创建了这些函数,但不知道如何让它们在问题中运行
function displayManutdCrest() {
document.getElementById('crest').src='assets/images/image2.png'
}
function displayMillwallCrest() {
document.getElementById('crest').src='assets/images/image3.png'
}
我只是在学习 JS,如果这没有意义,我深表歉意
慕容森
相关分类