- HTMLとJavaScriptの下準備をする
- クリック処理を実装する(コールバック関数を直接埋め込む)
- 【おまけ】クリック処理を実装する(定義済みの関数をコールバック関数として使う)
-
-
Save tsuyopon-xyz/38c555b5696cd3d2dfdd795f9dd888ca 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"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>クリック処理のテスト</title> | |
</head> | |
<body> | |
<h1 id="logo">ここをクリック!</h1> | |
<script src="./main.js"></script> | |
</body> | |
</html> |
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 logo = document.getElementById('logo'); | |
const onClick = () => { | |
console.log('クリックされた in onClick関数!'); | |
}; | |
logo.addEventListener( 'click', onClick ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment