私は動物の写真を表示するために異なるボタンをクリックすると、画像ソースをどのように変更できるかを調べようとしています。私のJSコードは、私のHTML文書の先頭にあるスクリプトタグの中間です。私はそれを下に貼り付けた。私はSafariを使用しています。クリックするとJavaScriptで画像ソースを変更できますか?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome</title>
<link rel="stylesheet" href="styles.css">
<script>
function change(){
document.getElementById("pic").src="./images/lion.jpg";
}
</script>
</head>
<body>
<header>
<div class="container">
<h1>Choose an Animal</h1>
<hr>
</div>
</header>
<section>
<div class="container">
<img src="./images/image.jpg" id="pic">
</div>
</section>
<section id="animals">
<div class="container">
<button type="button" class="button1" onclick="change">Lion</button>
<button type="button" class="button1">Tiger</button>
<button type="button" class="button1">Bear</button>
</div>
</section>
</body>
</html>
どのようなエラーが表示されますか? –