3 回答
TA贡献1817条经验 获得超14个赞
您忘记关闭“ :
<!DOCTYPE html>
<html>
<head>
<header></header>
<link rel="stylesheet" type="text/css" href="C.css">
<body>
<p> <font face="Times New Roman" size=18> Parakeet Images </font> </p>
<img id="parakeet" src="green_parakeet.jpg" />
<button onclick="g()">Show Green!</button>
<script>function g(){document.getElementById('parakeet').src="green_parakeet.jpg";}</script>
<button onclick="b()">Show Blue!</button>
<script>function b(){document.getElementById('parakeet').src="blue_parakeet.jpg";}</script>
</body>
</html>
TA贡献1868条经验 获得超4个赞
您的两个脚本中都缺少结束引号
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="C.css">
</head>
<body>
<p> <font face="Times New Roman" size=18> Parakeet Images </font> </p>
<img id="parakeet" src="green_parakeet.jpg" src="blue_parakeet.jpg" />
<button onclick="g()">Show Green!</button>
<script>function g(){document.getElementById('parakeet').src="green_parakeet.jpg"}</script>
<button onclick="b()">Show Blue!</button>
<script>function b(){document.getElementById('parakeet').src="blue_parakeet.jpg"}</script>
</body>
</html>
TA贡献1803条经验 获得超3个赞
您的代码是正确的,只是您在图像名称末尾缺少“并且元素src中有额外的标签img。
function b() {
document.getElementById('parakeet').src = "https://dummyimage.com/600x400/209de6/fff";
}
function g() {
document.getElementById('parakeet').src = "https://dummyimage.com/600x400/20e62a/fff";
}
<!DOCTYPE html>
<html>
<head>
<header></header>
<link rel="stylesheet" type="text/css" href="C.css">
<body>
<p>
<font face="Times New Roman" size=18> Parakeet Images </font>
</p>
<img id="parakeet" src="https://dummyimage.com/600x400/20e62a/fff" />
<button onclick="g()">Show Green!</button>
<button onclick="b()">Show Blue!</button>
</body>
</html>
添加回答
举报