Custom events in javascriptz

Source: Internet
Author: User
In the development of Ajax applications Program If you can customize JavaScript events, it will be a very pleasant thing, but it is really difficult to develop JS into event handlers like MFC or C. So Google found some methods for developing JavaScript custom events and wrote a simple example program:

< Html >
< Head >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charsets = iso-8859-1"   />
< Script SRC = "Yahoo-min.js" > </ Script >
< Script SRC = "Event-min.js" > </ Script >
< Script Language = "JavaScript" >
VaR Onlogin = New Yahoo. util. customevent ( " Onlogin " );
Function Hilogin ()
{
Alert ( " Hello " );
}
Function Hilogin1 ()
{
Alert ( " Hello111 " );
}
Onlogin. subscribe (hilogin );
Onlogin. subscribe (hilogin );
Onlogin. subscribe (hilogin1 );

Function Btcl ()
{
Window. Status = " Click button " ;
Onlogin. Fire ();
}
</ Script >
</ Head >
< Body >
< Input Type = "Button" Title = "Click me" Onclick = "Btcl ()" Value = "Click me" />
</ Body >
</ Html >

Note:
1. The Yahoo JS Development Kit is used. Generally, there are two Yahoo JS files. One is the original version, the other is the min version, and the other is the same as the original version, why is it so small? Because all comments, line breaks, and spaces are deleted, and variable names are represented by the least characters, they are much smaller.
2 Yahoo event packages include common event subscription and other functions, which are much easier to use than developing a set of Event Routing programs.

For ease of analysis, the class structure of the two JS packages is posted as follows:
Yahoo. JS:


Event. JS:


Reference address:
Http://developer.yahoo.com/yui/event/ Yahoo
Http://www.dustindiaz.com/custom-events/ web standards with imagination

Source codeDownload
Yahoo_event_test

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.