JavaScript 코드 내에 이벤트 핸들러를 등록하면 "this" 문을 사용할 수 있습니다. JavaScript 함수에 값을 전달할 필요가 없습니다. 대신 "this"를 사용하여 속성을 조작하세요.
예시를 보자
라이브 데모
<!DOCTYPE html>
<html>
<head>
<script>
function display( ) {
click.onclick = styleMe;
uname.onclick = styleMe;
}
function styleMe ( ) {
this.style.backgroundColor = "#000000";
this.style.color = "#FFFFFF";
}
</script>
</head>
<body onload="display()" >
<div id="uname"> Hello Wordl!</div>
<button id="click"> Click</button>
</body>
</html>