동물의 그림을 보여주기 위해 다른 버튼을 클릭 할 때 이미지 소스를 어떻게 바꿀 수 있는지 알아 내려고합니다. 내 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>
어떤 종류의 오류가 발생하고 있습니까? –