我今天刚遇到这个问题并开发了以下解决方案。
$("select").change(function() {
// Ignore events if the interval has already been established
if (this.interval)
return false;
// Self invoking anonymous function to prevent polution of parent scope
// in some environments (IE), passes 'this' as element
(function (element) {
// Set an interval to watch for the window to close
element.interval = setInterval((function callback() {
// Find the widget
var $widget = $('#'+element.id+'-menu').closest('.ui-selectmenu');
// If it has been closed DO STUFF and clear the interval
if ($widget.hasClass('ui-selectmenu-hidden')) {
// YOUR CODE HERE
clearInterval(element.interval);
}
return callback;
})(), 1000);
})(this);
return false;
});
另外值得注意的是,如果您通过 ajax 重新加载这些表单元素,则需要在插入新 HTML 之前从 DOM 中删除自定义小部件元素。动态更新选项将是一个更优雅的解决方案,但我没有那个选项。
$('.ui-selectmenu, .ui-selectmenu-screen, .ui-dialog').remove();