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>