2014-01-21 32 views
0

我有一個非常基本的形式來充當模式對話框和按鈕。這裏是我的代碼片段:JQueryUI對話框將不會打開

this.element.find('.column-chooser').dialog({ 
    'autoOpen':false, 
    'modal':true, 
    'height':300, 
    'width':300 
}); 

this.element.find('.choose-cols').button().on('click', function() { 
    this.element.find('.column-chooser').dialog('open'); 
    alert('Hello, world!'); 
}.bind(this)); 

(我使用「this.element.find」,而不是「$」的原因是因爲這是動態應用的原型對象)。

截至目前,如果我設置'autoOpen:true'而不是false,那麼對話框就顯示得很好。點擊我的按鈕'choose-cols'類會彈出我的「Hello,World!」警告框,但它不會打開對話框。另外,這段代碼片段:

this.element.find('.column-chooser').dialog('open'); 

直接在對話框定義後插入也不會打開對話框。這就好像我的JS完全忽略了'open'命令。有任何想法嗎?

回答

0

嘗試

this.element.find('.choose-cols').button().live('click', function() { 
this.element.find('.column-chooser').dialog('open'); 
alert('Hello, world!'); 

} .bind(本));

正如我所知的動態添加對象ON無法正常工作。嘗試使用LIVE而不是ON。

+0

嘗試.live()它只是打破了其餘的JS。此外,雖然,我不認爲這是有問題的點擊事件。警報('Hello,world!')觸發得很好,但對話框沒有打開。謝謝! – user3124101