<script type="text/javascript">
window.onload = function(){
console.log('window onload');
};
</script>
function doProcess(){
var result = document.getElementById("result");
result.innerHTML = "<span>이벤트 결과</span>";
}
</script>
</head>
<body>
<input type="button" value="버튼1" onclick="doProcess()">
<input type="button" value="버튼2">
<div id="result"></div>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type='text/javascript'>
window.onload = function(){
//변수 선언
var event = document.getElementById('clickButton');
// 이벤트 연결
event.onclick = function(){
alert('클릭');
};
};
</script>
</head>
<body>
<input type ="button" id="clickButton" value = "버튼">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
window.onload = function(){
function clickEvent(){
alert("클릭!");
}
function updateValue(event){
this.value = '눌렀다';
}
var btn = document.getElementById("btn");
btn.addEventListener("click", clickEvent);
btn.addEventListener("click", updateValue);
}
</script>
</head>
<body>
<input type="button" id="btn" value="button"/>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
*{border:3px solid black;}
</style>
<script>
</script>
</head>
<body>
<div onClick="alert('outer-div')">
<h1 onclick="alert('header')">
<p onclick="alert('paragraph')">Paragraph</p>
</h1>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
*{border:3px solid black;}
</style>
<script>
var paragraph_func = function paragraphfunc(e){
var event = e || window.event;
// 이벤트 발생을 알립니다
alert('paragraph');
// 이벤트 전달을 제거합니다
event.cancelBubble = true;
if(event.stopPropagation){
event.stopPropagation();
}
}
var header_func = function headerfunc(e){
var event = e || window.event;
// 이벤트 발생을 알립니다
alert('header');
// 이벤트 전달을 제거합니다
event.cancelBubble = true;
if(event.stopPropagation){
event.stopPropagation();
}
}
</script>
</head>
<body>
<div onClick="alert('outer-div')">
<h1 onclick='header_func(event);'>
<p onclick='paragraph_func(event);'>Paragraph</p>
</h1>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
window.onload = function(){
var header = document.getElementById('my-header');
if(header.attachEvent){ // 구형 버전은 attach. 존재한다면 구형이란 뜻. 신형은 eventListener
// 인터넷 익스플로러의 경우 실행
var hanndler = function(){
window.event.srcElement.style.color = 'red';
window.event.srcElement.detachEvent('onClick', handler);
};
header.attachEvent('onClick', handler);
}else {
// 그 이외의 브라우저에 실행합니다
var handler = function(){
this.style.color = 'red';
this.removeEventListener('click', handler);
};
header.addEventListener('click', handler);
}
}
</script>
</head>
<body>
<h1 id = "my-header">Click</h1>
</body>
</html>