Javascript _ multi-event registration example

Source: Internet
Author: User

<! 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>

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.