0

我认为我的 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>
4

1 回答 1

-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>
于 2013-10-31T01:46:28.270 回答