포커스 이벤트는 요소가 포커스를 얻거나 잃을 때 시작됩니다. 다음은 focusevents입니다 -
| 이벤트 | 설명 |
|---|---|
| 흐림 효과 | 이 이벤트는 요소가 포커스를 잃으면 시작됩니다. |
| 포커스 | 이 이벤트는 요소가 포커스를 받으면 시작됩니다. |
| 집중 | 이 이벤트는 요소가 포커스를 얻으려고 할 때 시작됩니다. |
| 오쿠스아웃 | 이 이벤트는 요소가 포커스를 잃을 때 시작됩니다. |
다음은 JavaScript의 포커스 이벤트에 대한 코드입니다 -
예시
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
input {
padding: 10px;
}
</style>
</head>
<body>
<h1>Focus events in Javascript</h1>
<form id="form">
<input type="text" placeholder="Username" />
<input class="passW" type="password" placeholder="Password" />
</form>
<h3>Focus on the above password input box to change its background color</h3>
<script>
let passEle = document.querySelector(".passW");
passEle.addEventListener("focus", () => {
passEle.style.backgroundColor = "#90EE90";
});
</script>
</body>
</html> 출력

비밀번호 필드에 초점 -
