Last active
May 31, 2021 15:49
-
-
Save sounisi5011/4b87ccefe3380230a938ff64ec6b2840 to your computer and use it in GitHub Desktop.
ボタンで画像を切り替えるサンプルページ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang=ja> | |
<meta charset=utf-8> | |
<meta name=viewport content="width=device-width,initial-scale=1"> | |
<meta name=format-detection content="telephone=no,email=no,address=no"> | |
<title>ボタンで画像を切り替えるサンプルページ</title> | |
<h1>ボタンで画像を切り替えるサンプルページ</h1> | |
<p><img id="image" src="http://placekitten.com/300/200"> | |
<p> | |
<button id="show-kitten">ネコ</button> | |
<button id="show-bear">クマ</button> | |
<button id="show-bacon">ベーコン</button> | |
<footer> | |
<h2>Gist</h2> | |
<p><a href="https://gist.github.com/sounisi5011/4b87ccefe3380230a938ff64ec6b2840">gist.github.com<wbr>/sounisi5011<wbr>/4b87ccefe3380230a938ff64ec6b2840</a> | |
</footer> | |
<script src="./main.js" defer></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const imageElem = document.getElementById('image'); | |
document.getElementById('show-kitten').addEventListener('click', () => { | |
imageElem.src = 'http://placekitten.com/300/200'; | |
}); | |
document.getElementById('show-bear').addEventListener('click', () => { | |
imageElem.src = 'http://placebear.com/300/200'; | |
}); | |
document.getElementById('show-bacon').addEventListener('click', () => { | |
imageElem.src = 'http://baconmockup.com/300/200'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment