Asp.Net ajax 面向对象类型系统2 - 使用事件
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Asp.Net ajax 面向对象类型系统2 - 使用事件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                直接上代碼了:
//注冊命名空間 Type.registerNamespace("MyNamesapce");MyNamesapce.Eat = function() {//定義EventHandlerList對象// this._events = new Sys.EventHandlerList();this._events = null; } MyNamesapce.Eat.prototype ={_get_events: function(){if (!this._events){//返回EventHandlerList對象this._events = new Sys.EventHandlerList();}return this._events;},//添加add和remove eat事件的方法add_eatEvent: function(handler){this._get_events().addHandler("eat", handler);},remove_eatEvent: function(handler){this._get_events().removeHandler("eat", handler);},//定義eat事件onEat: function(e){var eatHandler = this._get_events().getHandler("eat");if (eatHandler){eatHandler(this, e);}},//定義觸發eat事件的方法handleEat: function(isHungry){if (isHungry){this.onEat(Sys.EventArgs.Empty);}}} MyNamesapce.Eat.registerClass("MyNamesapce.Eat"); //----------------------------------------------------------- function test() {var eat = new MyNamesapce.Eat();//添加eat事件注冊eat.add_eatEvent(EatEventMethod1);eat.add_eatEvent(EatEventMethod2);eat.add_eatEvent(EatEventMethod3);//觸發eat事件eat.handleEat(true); } //定義eat事件處理方法 function EatEventMethod1(sender, e) {alert("I begin to eat."); } function EatEventMethod2(sender, e) {alert("I am eating."); } function EatEventMethod3(sender, e) {alert("I've eaten."); }
其實這個和C#的EventHandlerList的事件處理方式差不多的,演示地址(查看源文件即是本例): 
http://www.xpp.com.cn/AspnetAjax/AjaxOO/MyEvents.aspx
轉載于:https://www.cnblogs.com/xpp123/archive/2009/12/27/1633681.html
總結
以上是生活随笔為你收集整理的Asp.Net ajax 面向对象类型系统2 - 使用事件的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: as3中使用字符串调用函数。
 - 下一篇: 详解Windows开机自动运行