我有以下幾點:如何取消jQuery UI對話框打開?
container.dialog().bind('dialogopen', function(event, ui)
{
...
if (someCondition)
{
$(this).dialog('close'); // the dialog is not closed!
}
}
我應該怎麼做工作?
不幸的是,沒有'beforeopen'事件被掛鉤。
我有以下幾點:如何取消jQuery UI對話框打開?
container.dialog().bind('dialogopen', function(event, ui)
{
...
if (someCondition)
{
$(this).dialog('close'); // the dialog is not closed!
}
}
我應該怎麼做工作?
不幸的是,沒有'beforeopen'事件被掛鉤。
這裏的問題是你需要綁定事件之前它發生。目前你打電話給.dialog()
打開對話框(除非autoOpen: false
是提供的選項)。這意味着在您的.bind(....)
運行之前,事件已經發生。解決的辦法是事件發生之前,只是結合,像這樣:
container.bind('dialogopen', function(event, ui) {
if (someCondition) {
$(this).dialog('close'); // the dialog is not closed!
}
}).dialog(); //.dialog() fires "dialogopen" as part of it's execution
You can view a demonstration here,它會阻止打開的對話框中,或者更確切地說,它確實開,但瞬間UI線程更新之前關閉,所以對用戶來說,它永遠不會打開。
這是可行的,因爲the dialogopen
event是在您轉換成對話框(而不是對話框容器)的元素上觸發的......稍後創建對話框本身無關緊要,這只是一個監聽事件的DOM元素。
調查autoOpen(將其設置爲false
)以保持隱藏狀態,直到您確認someCondition。然後調用.dialog("open")
...
對話框中的打開事件就像'beforeopen'。
是的。我想到了,但由於它是一個插件,我不能確定.dialog('open')的調用者是誰。也許我應該重新考慮我的設計。 – 2010-06-28 20:11:44