본문 바로가기
컴퓨터이야기/JavaScript

화살표 함수 예시2

by 변화지시자 2023. 3. 15.
반응형
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>

  <form method="post" action="">
	<input type="button" id="button" value="버튼">
  </form>
  <script>
/*
	const btn = document.querySelector("#button");
	function display() {
	   alert("클릭했습니다.");
	}
	btn.addEventListener("click", display);   //버튼을 클릭하면 display 함수 실행
*/

	const btn = document.querySelector("#button");
	btn.addEventListener("click", () => {
		alert("클릭했습니다.")
	})


  </script>
 </body>
</html>