Event.initEvent()
Устарело: Эта возможность была удалена из веб-стандартов. Хотя некоторые браузеры по-прежнему могут поддерживать её, она находится в процессе удаления. Не используйте её ни в старых, ни в новых проектах. Страницы или веб-приложения, использующие её, могут в любой момент сломаться.
Примечание: Эта возможность доступна в Web Workers.
The Event.initEvent() method is used to initialize the value of an event created using Document.createEvent().
Events initialized in this way must have been created with the Document.createEvent() 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 даст больше информации о возможностях использования.
Синтаксис
event.initEvent(type, bubbles, cancelable);
type-
DOMString, определяющая тип события. bubbles-
Is a
Booleandeciding whether the event should bubble up through the event chain or not. Once set, the read-only propertyEvent.bubbleswill give its value. cancelable-
Is a
Booleandefining whether the event can be canceled. Once set, the read-only propertyEvent.cancelablewill 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);
Спецификации
| Specification |
|---|
| DOM> # dom-event-initevent> |
Совместимость с браузерами
Loading…
Смотрите также
- The constructor to use instead of this deprecated method:
Event(). More specific constructors can be used too.