GlobalEventHandlers.onblur

Свойство onblur из GlobalEventHandlers событий event handler для blur (en-US) события. Оно доступно дляElement, Document и Window.

Событие blur возникает когда элемент теряет фокус.

Примечание: Обратным onblur является onfocus.

Syntax

target.onblur = functionRef;

Value

functionRef - это имя функции или function expression. Функция получает объект FocusEvent (en-US) в качестве единственного аргумента.

Example

В этом примере onblur и onfocus используются для изменения текста в элементе <input>.

HTML

html

<input type="text" value="CLICK HERE">

JavaScript

js

let input = document.querySelector('input');

input.onblur = inputBlur;
input.onfocus = inputFocus;

function inputBlur() {
  input.value = 'Focus has been lost';
}

function inputFocus() {
  input.value = 'Focus is here';
}

Result

Нажимайте внутри и вне поля формы. Содержимое будет изменятся.

Specifications

Browser compatibility

BCD tables only load in the browser

In contrast to IE, in which almost all kinds of elements receive the blur event, only a few kinds of elements on Gecko browsers work with this event.

See also