This page was translated from English by the community.Learn more and join the MDN Web Docs community.
Event.initEvent()
Устарело: Эта возможность была удалена из веб-стандартов. Хотя некоторые браузеры по-прежнему могут поддерживать её, она находится в процессе удаления. Не используйте её ни в старых, ни в новых проектах. Страницы или веб-приложения, использующие её, могут в любой момент сломаться.
Примечание: Эта возможность доступна вWeb Workers.
TheEvent.initEvent() method is used to initialize the value of anevent created usingDocument.createEvent().
Events initialized in this way must have been created with theDocument.createEvent() method. This method must be called to set the event before it is dispatched, usingEventTarget.dispatchEvent(). Once dispatched, it doesn't do anything anymore.
Примечание:Не используйте этот метод, т.к. он устаревший. (deprecated)
Вместо него используйте такой специальный конструктор событий, какEvent(). СтраницаCreating and triggering events даст больше информации о возможностях использования.
In this article
Синтаксис
event.initEvent(type, bubbles, cancelable);
typeDOMString, определяющая тип события.bubblesIs a
Booleandeciding whether the event should bubble up through the event chain or not. Once set, the read-only propertyEvent.bubbleswill give its value.cancelableIs 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 canceledevent.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> |
Совместимость с браузерами
Смотрите также
- The constructor to use instead of this deprecated method:
Event(). More specific constructors can be used too.