Switches between two images
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>版本1 - innerHTML 簡單切換</title>
</head>
<body>
<div id="photoContainer">
<img src="http://1.bp.blogspot.com/-xdHGOG59LCI/UjawN7V-deI/AAAAAAAABb8/v3dHRriJkjo/s1600/EUCL%E4%B8%8A%E5%8F%B0%E9%A0%98%E7%8D%8E01.jpg" width="300">
</div>
<br><br>
<button onclick="showPrev()">上一張</button>
<button onclick="showNext()">下一張</button>
<script>
let current = 1;
function showPrev() {
if (current > 1) {
current = current - 1;
document.getElementById("photoContainer").innerHTML =
'<img src="http://1.bp.blogspot.com/-xdHGOG59LCI/UjawN7V-deI/AAAAAAAABb8/v3dHRriJkjo/s1600/EUCL%E4%B8%8A%E5%8F%B0%E9%A0%98%E7%8D%8E01.jpg" width="300">';
}
}
function showNext() {
if (current < 3) {
current = current + 1;
document.getElementById("photoContainer").innerHTML =
'<img src="http://4.bp.blogspot.com/-UKB9Pburh8I/Ujawb7t3wGI/AAAAAAAABcE/2h3OMM1sb-0/s1600/Frocius+Android%E4%B8%8A%E5%8F%B0%E9%A0%98%E7%8D%8E01.jpg" width="300">';
}
}
</script>
</body>
</html>