我正在做一项任务,其中网页根据选定的单选按钮显示国家的国旗。该任务的目标是使用Javascript来更改img元素的src属性。我不相信我们应该使用功能,因为直到下一章才会介绍。我已经按照当前章节中的所有指南进行了讨论,但他们只讨论改变文字而不是图像。如何使用单选按钮更改img src与HTML5和Javascript
这里是我的代码:
<!DOCTYPE HTML>
<html>
<head>
<title>Flags</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<form name="CountryList" method="get">
<table>
<tr>
<td>
<input type="radio" name="country" onclick="document.ProductImage.src='argentina.jpg'" />Argentina
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='australia.jpg'" />Australia
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='bolivia.jpg'" />Bolivia
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='cuba.jpg'" />Cuba
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='finland.jpg'" />Finland
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='france.jpg'" />France
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='italy.jpg'" />Italy
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='peru.jpg'" />Peru
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='syria.jpg'" />Syria
<br />
<input type="radio" name="country" onclick="document.ProductImage.src='tunisia.jpg'" />Tunisia
</td>
<td>
<a><img id="ProductImage" src="" alt="Flag" /></a>
</td>
</tr>
</table>
</form>
</body>
</html>
可能有人点我在正确的方向还是让我知道,如果它是不可能更改,恕不功能的IMG SRC属性?
谢谢!
不要忘记选择你的答案,一旦你找到了一个。 – 2013-03-12 20:13:48