我正在嘗試製作特定糖果彈出的圖像,當您鍵入其名稱但只有Ghirardelli的作品。爲什麼不是這個javascript提示工作?
<p id="chocolate"></p>
<img src="hershey.jpg" id="pic">
<script>
var y = prompt("What would you like to see a picture of?");
if (y == "Hershey")
{
document.getElementById("chocolate").innerHTML="Hershey";
}
if (y == "Reeses")
{
document.getElementById("chocolate").innerHTML="Reeses";
document.getElementById("pic").src="reeses.jpg";
}
if (y == "Ghiradelli")
{
document.getElementById("chocolate").innerHTML="Ghiradelli";
document.getElementById("pic").src="ghiradelli.jpg";
}
else
{
document.getElementById("chocolate").innerHTML="Please choose one of these three things: <ul><li>Hershey</li><li>Reeses</li><li>Ghiradelli</li></ul>";
document.getElementById("pic").src="x.svg";
}
</script>
如此,甚至沒有賀喜的作品? –
甚至不hershey –
,但它確實顯示頁面加載hershey,右 –