当src存储在数组中时,通过javascript更改imgsrc
我正在尝试更改页面加载时图像的来源,但不是加载图像本身,而是显示其位置的字符串。很可能是一个简单的解决方案,但我看不到当src存储在数组中时,通过javascript更改imgsrc,javascript,html,Javascript,Html,我正在尝试更改页面加载时图像的来源,但不是加载图像本身,而是显示其位置的字符串。很可能是一个简单的解决方案,但我看不到 <form id="form1"><h1 id="dude">question?</h1><br> <h2> <label for ="answer1" id="label1"><img src="imgs//im
<form id="form1"><h1 id="dude">question?</h1><br>
<h2>
<label for ="answer1" id="label1"><img src="imgs//img.png" id="img1" width="150" height = "150"></label>
<input type="radio" name="answer" id="answer1">
</h2><br>
<h2>
<label for ="answer2" id="label2"><img src="imgs//img.png" id="img2" width="150" height = "150"></label>
<input type="radio" name="answer" id="answer2">
</h2><br>
<h2>
<label for="answer3" id="label3"><img src="imgs//img.png" id="img3" width="150" height = "150"></label>
<input type="radio" name="answer" id="answer3">
</h2>
<h2>
<label for="answer4" id="label4"><img src="imgs//img.png" id="img4" width="150" height = "150"></label>
<input type="radio" name"answer" id="answer4">
</h2>
</form>
如果您有任何想法,我们将不胜感激。您实际上并没有更改图像的src,而只是更改Label元素的innerHtml 您需要从标签中获取图像元素,然后执行image.src=coi[currentQuestion][1] 你可以用这个
var mulChoiImg = new Array('Which picture do you like most', 'imgs/img2.png','imgs/img2.png','imgs//img2.png','imgs/img2.png');
function popMulC(){
document.getElementById("label1").innerHTML = "<img src=" + mulChoiImg[1] + "/>";
}
您正在使用双斜杠imgs//删除一个。仍然没有更改吗?
var mulChoiImg = new Array('Which picture do you like most', 'imgs/img2.png','imgs/img2.png','imgs//img2.png','imgs/img2.png');
function popMulC(){
document.getElementById("label1").innerHTML = "<img src=" + mulChoiImg[1] + "/>";
}