Javascript 在对象创建时添加事件处理程序不会';不行?
我有以下资料:Javascript 在对象创建时添加事件处理程序不会';不行?,javascript,jquery,javascript-objects,dom-events,Javascript,Jquery,Javascript Objects,Dom Events,我有以下资料: MycheckModal.__construct = function(element){ this.blackout = $("<div class='modal-backdrop'></div>") .attr("style", 'left:0px;top:0px;position:absolute;background:black') .css("opacity", "0.5") .css("height", $(docume
MycheckModal.__construct = function(element){
this.blackout = $("<div class='modal-backdrop'></div>")
.attr("style", 'left:0px;top:0px;position:absolute;background:black')
.css("opacity", "0.5")
.css("height", $(document).height() + 'px')
.css("width", $(document).width() + 'px')
.css("z-index", "5000");
this.blackout.live("click", function(){
MycheckModal.__destruct();
});
}
MycheckModal.__destruct = function(){
this.element = null;
this.url = null;
this.blackout.fadeOut(150, function(){
MycheckModal.blackout.remove();
MycheckModal.blackout = null;
} );
this.modal.fadeOut(150, function(){
MycheckModal.modal.remove();
MycheckModal.modal = null;
} );
}
MycheckModal.\uu构造=函数(元素){
this.blackout=$(“”)
.attr(“样式”,“左:0px;顶:0px;位置:绝对;背景:黑色”)
.css(“不透明度”、“0.5”)
.css(“height”,$(document).height()+“px”)
.css(“宽度”,$(文档).width()+“px”)
.css(“z指数”、“5000”);
this.blackout.live(“单击”,函数()){
MycheckModal._destruct();
});
}
MycheckModal.\uuu destruct=函数(){
this.element=null;
this.url=null;
this.blackout.fadeOut(150,function(){
MycheckModal.blackout.remove();
MycheckModal.blackout=null;
} );
this.modal.fadeOut(150,function(){
MycheckModal.modal.remove();
MycheckModal.modal=null;
} );
}
这是一个更大的代码,但你得到了jist。
无论如何-事件处理程序没有注册,但是-当我在构造函数外部显式注册它时-它工作正常
你知道我需要做什么吗?我不知道为什么,但试着用“点击”代替“直播”
this.blackout.click(function() {
MycheckModal.__destruct();
});
this.blackout.on("click", function(){
MycheckModal.__destruct();
});