언젠가 쓸일 있을 때 찾아보려고 Keep!
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset = "UTF-8">
<title> 함수 </title>
<style>
*{margin: 0;padding: 0;}
#galleryZone {text-align: center;}
#galleryZone input[type="image"]{margin:0 8px;}
</style>
<script>
var num = 1;
function gallery(direct) {
if(direct) {
if(num == 8) return; //여기서 8은 최대치를 뜻한다.!
num++;
} else {
if(num == 1) return;
num--;
}
var imgTag = document.getElementById("photo");
imgTag.setAttribute("src","images/pic_" + num + ".jpg");
}
</script>
</head>
<body>
<div id="galleryZone">
<p><img src="images/pic_1.jpg" id="photo" alt=""></p>
<p>
<button onclick="gallery(0)">이전</button>
<button onclick="gallery(1)">다음</button>
</p>
</div>
</body>
</html>