2012-04-18 10 views
1

オブジェクト作成時にイベントハンドラを追加できない?私は、次のJavaScriptき

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; 
     });  
} 

をそれは少し大きなコードですが、あなたはJISTを取得します。とにかく - イベントハンドラは登録されていませんが、明示的に登録するときはコンストラクタの外で動作します。

私は何をする必要がありますか?

答えて

1

なぜか分かりませんが、「ライブ」ではなく「クリック」を使用してみてください。

this.blackout.click(function() { 
    MycheckModal.__destruct(); 
}); 
1
this.blackout.on("click", function(){ 
    MycheckModal.__destruct(); 
}); 
関連する問題