JS Manual trigger Event, reprint

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.