我已经建立了有私人/公共领域/方法,我有低于简化 DOM对象引擎:如何动态注册jQuery自定义事件?
function Engine(args){
this.display = args.display;
this.getDisplay = function(){return this.display;}
this.alertMsg = function(msg){
console.log(this.display);
alert(msg);
}
}
我想这样做的是建立,将在alert(msg)
后触发自定义事件如$(this.display).trigger("afterAlert");
function Engine(args){
this.display = args.display;
this.getDisplay = function(){return this.display;}
this.alertMsg = function(msg){
console.log(this.display);
alert(msg);
// trigger custom event here
$(this.display).trigger("afterAlert");
}
}
现在,这个事件可能是空的或不是。如何将一个或多个对象声明为以后注册到“afterAlert”事件?在我的情况下,额外的JavaScript文件是通过动态的主文件加载,并可能包含一个代码ressembling:
function new_obj(){
bind("afterAlert", function(){
alert("alert was called");
});
}
我不能让它工作...是有可能绑定触发器被声明之后? – karlipoppins 2009-08-13 14:06:22
触发器是调用函数....这里是另一个演示,当我有第二个按钮,附加一个新的用户元素,并再次触发。观看ff控制台http://pastebin.me/1d9a8ac9e8c8cd7de3cd5e71d8583c20 – redsquare 2009-08-13 14:11:11
明白了!非常感谢! :) – karlipoppins 2009-08-13 14:13:07