我认为我的if / else语句有问题导致此代码无效。我已经尝试更改id并使用document.canvas.src而不是getElementById,但它不会对我有任何影响。
更新:下面是我用来使其正常运行的代码:
<HTML>
<HEAD>
<script type = "text/javascript">
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" id="animal">
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
答案 0 :(得分:-1)
实际上它适用于IE 10,可能您可以尝试更正选项标签:
<select name="imageSelector" onChange="displayImage(this.value)">
<option value="noImage">Select an Animal</option>
<option value="dog.jpg">Dog</option>
<option value="cat.jpg">Cat</option>
<option value="parrot.jpg">Parrot</option>
<option value="fish.jpg">Fish</option>
<option value="alligator.jpg">Alligator</option>
<option value="mouse.jpg">Mouse</option>
<option value="fox.jpg">Fox</option>
</select>