我还有另一个 Javascript 问题,我真的可以使用帮助。对于这些愚蠢的问题,我再次感到抱歉,但我对此真的很陌生,我只是不知道自己在做什么。到目前为止,我有我需要的代码,然后在脚本中注释我缺少的信息。
谢谢!
<HTML>
<HEAD>
<script>
//build a function named displayImage
//it should be catching the value of the item selected in a variable named whichImage
//use an if / else structure to test for whichImage not being equal to the string "noImage"
//if the statement is true then display the selected image in the canvas image
//if the statement is false then display the "blank.jpg" external file in the canvas image
//In the select tag below add an onChange event handler that calls the displayImage function
//the value property of the selection list should be passed to the displayImage function as it is called
//hint (this.value)
function displayImage(whichImage)
{
if(whichImage != "noImage")
{
document.canvas.src = whichImage;
}
else
{
document.canvas.src = "blank.jpg";
}
}
</script>
</HEAD>
<BODY>
<form name="imageForm">
<table border=3>
<tr>
<td>
<select name="imageSelector" onchange = "displayImage(this.value)">
<option value="noImage">Select an Animal
<option value="dog.jpg">Dog
<option value="cat.jpg">Cat
<option value="parrot.jpg">Parrot
<option value="fish.jpg">Fish
<option value="alligator.jpg">Alligator
<option value="mouse.jpg">Mouse
<option value="fox.jpg">Fox
</select>
</td>
</tr>
<tr>
<td>
<img src="blank.jpg" name="canvas">
</td>
</tr>
</table>
</form>
</BODY>
</HTML>