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