<A href = "javascript: Alert ('click')" id = "start"> click me </a>
<A href = "javascript: Document. getelementbyid ('start'). Click ()"> click Start </a>
The above process can be executed in IE, but cannot be executed in Firefox.
Only input elements can be assigned according to W3C standard click method.
Reference: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-6043025
Refer to the online method:
Function invokeclick (element ){
If (element. Click) element. Click ();
Else if (element. fireevent) element. fireevent ('onclick ');
Else if (document. createevent ){
VaR EVT = Document. createevent ("mouseevents ");
EVT. initevent ("click", true, true );
Element. dispatchevent (EVT );
}
}
NOTE 1: In Firefox, non-input elements still do not work.
NOTE 2: In IE8, the click method is executed on the <input type = File> File Upload control. Only the code bound to The onclick event of this element can be executed, the file selection dialog box does not pop up.
========================================================== ========================================================== ======
Void initevent (string eventtypearg, Boolean canbubblearg, Boolean cancelablearg)
The initevent method is used to initialize the value of the event created through the deleentevent interface. This method can only be called before the event is assigned through the dispatchevent method, although it can be called multiple times at this stage (if necessary ). If it is called multiple times, the last call takes precedence. If it is called from the subclass of the event interface, only the value specified in the initevent method is modified, and all other attributes remain unchanged.
Parameters:
Eventtypearg-specifies the event type. This type can be any event type defined in this specification or a new event type. The string must be an XML name. Any new event type must not start with an uppercase, lowercase, or mixed-case version of the string "dom. This prefix is reserved for future DOM Event sets. We strongly recommend that third parties who add their own events use their own prefixes to avoid confusion and reduce the possibility of conflicts with other new events.
Canbubblearg-specifies whether the event can be bubble.
Cancelablearg-specifies whether the default action of the event can be blocked.