Event.initEvent()

Устарело: Эта возможность была удалена из веб-стандартов. Хотя некоторые браузеры по-прежнему могут поддерживать её, она находится в процессе удаления. Не используйте её ни в старых, ни в новых проектах. Страницы или веб-приложения, использующие её, могут в любой момент сломаться.

The Event.initEvent() method is used to initialize the value of an event created using Document.createEvent() (en-US).

Events initialized in this way must have been created with the Document.createEvent() (en-US) method. This method must be called to set the event before it is dispatched, using EventTarget.dispatchEvent(). Once dispatched, it doesn't do anything anymore.

Примечание: Не используйте этот метод, т.к. он устаревший. (deprecated)

Вместо него используйте такой специальный конструктор событий, как Event(). Страница Creating and triggering events (en-US) даст больше информации о возможностях использования.

Синтаксис

event.initEvent(type, bubbles, cancelable);
type

DOMString, определяющая тип события.

bubbles

Is a Boolean deciding whether the event should bubble up through the event chain or not. Once set, the read-only property Event.bubbles will give its value.

cancelable

Is a Boolean defining whether the event can be canceled. Once set, the read-only property Event.cancelable will give its value.

Пример

// Create the event.
var event = document.createEvent('Event');

// Create a click event that bubbles up and
// cannot be canceled
event.initEvent('click', true, false);

// Listen for the event.
elem.addEventListener('click', function (e) {
  // e.target matches elem
}, false);

elem.dispatchEvent(event);

Спецификация

Спецификация Статус Комментарий
DOM
Определение 'Event.initEvent()' в этой спецификации.
Живой стандарт Начиная с Document Object Model (DOM) Level 2 Events Specification - deprecated, заменено на event constructors.
Document Object Model (DOM) Level 2 Events Specification
Определение 'Event.initEvent()' в этой спецификации.
Устаревшая Начальное определение.

Browser compatibility

BCD tables only load in the browser

Смотрите также

  • The constructor to use instead of this deprecated method: Event(). More specific constructors can be used too.