差不多兩年後纔回答這個問題,但我遇到了同樣的問題,最後我想分享一個更簡單的解決方案。
默認情況下,jQuery UI對話框在拖動時會忽略.ui-dialog-content(對話框的內容)和.ui-dialog-titlebar-close(標題元素中右上角的關閉按鈕)。這是用下面的代碼完成的:
this.uiDialog.draggable({
cancel: ".ui-dialog-content, .ui-dialog-titlebar-close",
...
});
這是添加到標題元素的任何東西所需的相同行爲。我能夠通過使用下面的代碼到我的下拉列表添加到拖動「刪除清單」:
$(dialog).appendTo('body').showDialog({
...
dialogClass: 'dialog-quick-select',
open: function(event, ui) {
var dropdownHtml = '<select id="market-set-dropdown"></select>';
var $currentDialog = $('.dialog-quick-select');
$('.ui-dialog-titlebar', $currentDialog).append(dropdownHtml);
//this is needed to allow the dropdown to be opened.
$currentDialog.draggable({
cancel: '.ui-dialog-content, .ui-dialog-titlebar-close, #market-set-dropdown'
});
}
});
我加入我的下拉在打開的方法,這就是爲什麼我選擇了修改取消那裏。另請注意,我的代碼依賴於分配給對話框的自定義類名,該對話框使用dialogClass選項設置。
還有一點需要注意,如果對話框預先定義的類名不斷變化(.ui-dialog-content和.ui-dialog-titlebar-close),取消將不再適用於這些元素。
的jQuery用戶界面對話框API:http://api.jqueryui.com/dialog/
能否請您發表您的實現? – karim79 2012-02-06 15:56:13
Here:[http://jsfiddle.net/a9ntp/](http://jsfiddle.net/a9ntp/) – 2012-02-06 16:03:47
你不知道我在想什麼。你不是心靈的。 – 2012-02-06 16:09:18