<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> multi-event registration mechanism </title>
<SCRIPT type = "text/JavaScript">
Function bodyload () {// Note: After the file is loaded, it cannot start to process;
VaR dom_a = Document. getelementbyid ("youdao ");
Dom_a.onclick = function () {// overwrite the embedded code;
Alert ("original event model ;");
}
// Register multiple events for click events of tag
Function addevent (element, type, FN) {// compatible with event processing;
If (element. addeventlistener ){
Element. addeventlistener (type, FN, false );
} Else if (element. attachevent ){
Element. attachevent ("On" + type, FN );
}
}
Function doclickevent1 (){
Alert ("first business processing for multi-event registration ;");
}
Function doclickevent2 (e ){
E = E | window. event; // because the event object of the IE event model is not passed to the Event Handler through parameters, it is stored in the window object;
Alert ("second business processing for multi-event registration ;");
If (E. preventdefault ){
E. preventdefault ();
} Else {
// E. returnvalue = false; // prevents jump to the specified URL;
Return false;
// It can also be blocked;
}
}
Addevent (dom_a, 'click', doclickevent1 );
Addevent (dom_a, "click", doclickevent2 );
}
</SCRIPT>
</Head>
<Body onload = "bodyload ()">
Demonstrate multi-event registration mechanism: <br/>
<A id = "youdao" onclick = "alert ('will it be overwritten? '); "Href =" http://fanyi.youdao.com/"> youdao translation </a>
</Body>
</Html>