1. CreateEvent (EventType)
Parameters: EventType A total of 5 types:
Events: Includes all the events.
Htmlevents: Includes ' abort ', ' blur ', ' Change ', ' error ', ' Focus ', ' load ', ' reset ', ' resize ', ' scroll ', ' SELECT ',
' Submit ', ' unload '. Event
Uieevents: Including ' domactivate ', ' domfocusin ', ' domfocusout ', ' KeyDown ', ' keypress ', ' KeyUp '.
Indirectly contains mouseevents.
Mouseevents: Includes ' click ', ' MouseDown ', ' MouseMove ', ' mouseout ', ' mouseover ', ' MouseUp '.
Mutationevents: Including ' domattrmodified ', ' domnodeinserted ', ' domnoderemoved ',
' Domcharacterdatamodified ', ' domnodeinsertedintodocument ',
' Domnoderemovedfromdocument ', ' domsubtreemodified '.
2. After the CreateEvent must be initialized, for you to introduce 5 kinds of corresponding initialization method
Htmlevents and General Events:
Initevent (' type ', Bubbles, cancelable)
Uievents:
Inituievent (' type ', Bubbles, cancelable, windowobject, detail)
Mouseevents:
Initmouseevent (' type ', Bubbles, cancelable, windowobject, detail, ScreenX, ScreenY,
ClientX, ClientY, Ctrlkey, Altkey, Shiftkey, Metakey, button, Relatedtarget)
Mutationevents:
Initmutationevent (' type ', Bubbles, cancelable, Relatednode, Prevvalue, NewValue,
Attrname, Attrchange)
3. After the initialization is complete, you can trigger the required events at any time, to introduce Targetobj.dispatchevent (event)
Triggering event events for Targetobj objects
Note that in the IE 5.5+ version, please use the FireEvent method, or browse compatibility considerations
4. Example
Example 1 immediate trigger mouse down event
var fireonthis = document.getElementById (' Someid ');
var evobj = document.createevent (' mouseevents ');
Evobj.initmouseevent (' Click ', True, true, window, 1, N, 345, 7, V, False, False, True, FALSE, 0, NULL);
Fireonthis.dispatchevent (Evobj);
Example 2 a mouse movement event that considers compatibility
var fireonthis = document.getElementById (' Someid ');
if (document.createevent)
{
var evobj = document.createevent (' mouseevents ');
Evobj.initevent (' MouseMove ', true, false);
Fireonthis.dispatchevent (Evobj);
}
else if (document.createeventobject)
{
Fireonthis.fireevent (' onmousemove ');//compatible with IE
}
JS Manual trigger Event, reprint