我有這個測試代碼,除了自動完成功能在第二次打開對話框時停止工作以外,完美地工作。我需要使用html以這種方式打開對話框,因爲我希望它能夠快速打開,這是最好的方式。爲什麼自動完成功能第二次停止工作?jQuery自動完成只在對話框中工作一次
var $container = $('#container'),
$input = $container.find('input:eq(0)');
var source = new Array(2);
source[0] = { value: 1000, label: 'Description' };
source[1] = { value: 1001, label: 'Description' };
$input.autocomplete({ source: source });
var $dialog = $('<div></div>').dialog({
autoOpen: false,
modal: true,
beforeclose: function() { $dialog.html(''); }
});
$('#open').click(function() {
$dialog.dialog('open').html($container);
});
編輯:我這樣使用html的原因是因爲我想打開一個空的對話框來加速它。這樣做會使對話看起來更有反應。我想繼續以這種方式打開對話框。這個祕密依然存在,爲什麼事件處理程序和自動完成功能第二次停止工作,我以這種方式打開對話框? $ container或$ input中沒有任何更改。