2

我有几个div元素在某些时候用户可以隐藏。

发生这种情况时,jQuery('div').hide('blind').remove();会触发 a ,因此元素首先从视口中隐藏,然后从DOM中删除。当从DOM 中删除元素时,jQuery-UI会留下一些垃圾容器(每个 div 隐藏和删除一个垃圾 div):

<div class="ui-effects-wrapper" style="font-size: 100%; background: none repeat scroll 0% 0% transparent; border: medium none; margin: 0px; padding: 0px; position: relative; width: 1032px; height: 0px; float: none; overflow: hidden;"></div>

现在我正在删除它们,jQuery('divs-wrapper-selector').find('.ui-effects-wrapper').remove();但我想知道为什么jQuery-UI这样做以及这是否有副作用。

4

1 回答 1

3

您的.hide()通话没有及时结束.remove()。您需要为该.hide()方法提供回调,如下所示:

$('target-elem').hide('blind', function () {
  $(this).remove();
});

更多信息请参见http://api.jqueryui.com/hide/

于 2013-08-12T20:37:22.633 回答