Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter02 : 이벤트_개요 본문

WEB.JS/10.EVENT_JS

chapter02 : 이벤트_개요

GAWON 2023. 5. 22. 09:21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">

	
	// onload = init;	// 함수명만 필요함. 괄호 제거
	function init(){
		document.body.style.backgroundColor = "yellow";		// 마침표
		//document.body.style["background-color"] = "yellow";	// 대괄호
	}
	

	
</script>
</head>
<body onload="init()">

	<h1 onclick="location.href='http://www.google.com'">구글로 이동</h1>


	<input type="button" value="클릭" id="btn">
	<script type="text/javascript">
		var btn = document.querySelector("#btn");
		btn.onclick = function(){
			alert("clicked");
			
			btn.onclick = null;	// 이벤트 해제.
		}
	</script>
</body>
</html>

'WEB.JS > 10.EVENT_JS' 카테고리의 다른 글

chapter01 : 이벤트_개요  (0) 2023.05.22
chapter03 : 이벤트_객체  (0) 2023.05.22
chapter04 : 디폴트_이벤트  (0) 2023.05.22
chapter05 : 마우스_이벤트  (0) 2023.05.22
chapter06 : 키보드_이벤트  (0) 2023.05.22