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

chapter04 : 디폴트_이벤트 본문

WEB.JS/10.EVENT_JS

chapter04 : 디폴트_이벤트

GAWON 2023. 5. 22. 09:21
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	/*
		디폴트 이벤트 (기본 이벤트) : 원할 때 막을 수 있다.
		1. 폼을 submit 하면 모든 폼 요소를 보내고, 초기화 한다.
		2. <a> 태그를 클릭하면 페이지 이동한다.
	*/

	onload = function(){
		var form = document.querySelector("#form");
		var a = document.querySelector("#a");
		
		// 1. 폼 submit 방지
		form.onsubmit = function(e){
			e.preventDefault();
		}
		
		a.onclick = function(e){
			e.preventDefault();
		}
		
	}
</script>
</head>
<body>
	<form action="#" id="form">
		<input type="text">
		<input type="submit">
	</form>
	<br/>
	<a id="a" href="http://www.google.com">구글로 이동</a>
</body>
</html>

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

chapter02 : 이벤트_개요  (0) 2023.05.22
chapter03 : 이벤트_객체  (0) 2023.05.22
chapter05 : 마우스_이벤트  (0) 2023.05.22
chapter06 : 키보드_이벤트  (0) 2023.05.22
chapter07 : 키보드_이벤트  (0) 2023.05.22