onfocus 사용 요소가 HTML에서 포커스를 받을 때 스크립트를 실행하는 속성입니다.
예시
다음 코드를 실행하여 onfocus를 구현할 수 있습니다. 속성 -
<!DOCTYPE html>
<html>
<body>
<p>Enter subject name below,</p>
Subject: <input type = "text" id = "sname" onfocus = "display(this.id)">
<br>
<script>
function display(val) {
document.getElementById(val).style.background = "blue";
}
</script>
</body>
</html>