表单获取、或者失去光标。
- focus:获得焦点
- blur:失去焦点
示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text" value="请输入内容">
<script>
const input = document.querySelector('input')
input.addEventListener('focus', function () {
console.log('获得焦点')
})
input.addEventListener('blur', function () {
console.log('失去焦点')
})
</script>
</body>
</html>