17. 이벤트 등록
1) 이벤트 등록 방법
addEventListener() 를 이용하여 요소에 이벤트 등록
타켓.addEventListener("이벤트종류",function(){});
이벤트 종류
load : 로딩이 완료 되었을때
resize : 윈도우창 크기 변경되었을때
keydown
keyup
change
click
focus
mousedown
mouseup
mouseout
mouseover
mousemove
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>
</title>
</head>
<body>
<button class="btn"> 클릭 </button>
<button onclick="clickFunc()"> 클릭 2</button>
<script> // 17 이벤트 등록
//@1 자바스크립트로 이벤트 등록
const btn = document.querySelector(".btn");
btn.addEventListener("click",function(){
alert("버튼클릭");
});
//@2 <button onclick="alert('버튼클릭)">클릭</button> 과 동일
//@3
function clickFunc(){
for(let i = 0; i <10; i++){
if(i%2 ==0){
console.log("helloo"+i);
}
}
}
</script>
</body>
</html>