Simulate a mouseover event:
const ev = document.createEvent("MouseEvent");
ev.initMouseEvent("mouseover", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
document.getElementById("myDiv").dispatchEvent(ev);
Try it Yourself »
The createEvent()
method creates an event object.
The event must be of a legal event type, and must be initialized (dipatched) before use.
document.createEvent(
type)
Parameter | Description |
type | Required. The type of event. AnimationEvent ClipboardEvent DragEvent FocusEvent HashChangeEvent InputEvent KeyboardEvent MouseEvent PageTransitionEvent PopStateEvent ProgressEvent StorageEvent TouchEvent TransitionEvent UiEvent WheelEvent |
Type | Description |
Object | An Event object. |
document.createEvent()
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!