HTMLElement: phương thức blur()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Phương thức HTMLElement.blur() xóa tiêu điểm bàn phím khỏi phần tử hiện tại.
Cú pháp
js
blur()
Tham số
Không có.
Giá trị trả về
Không có (undefined).
Ví dụ
>Xóa tiêu điểm khỏi ô nhập văn bản
HTML
html
<input type="text" id="sampleText" value="Sample Text" /><br /><br />
<button type="button">Nhấp vào tôi để lấy tiêu điểm</button>
JavaScript
js
const textField = document.getElementById("sampleText");
const button = document.querySelector("button");
function focusInput() {
textField.focus();
// Ô nhập sẽ mất tiêu điểm sau 3 giây
setTimeout(() => {
textField.blur();
}, 3000);
}
button.addEventListener("click", focusInput);
Kết quả
Đặc tả kỹ thuật
| Specification |
|---|
| HTML> # dom-blur-dev> |