找到删除 JQuery Accordion 时容器的长度?
我有以下代码来删除动态生成的 ui-accordion。当删除发生时(有效),我需要查明作为 div 的手风琴容器是否为空。因此,如果用户删除手风琴并且容器 div 现在为空,我需要调整包含的 div 的大小(该 div 是 ui.layout 窗格,当容器为空时,我需要自动为用户调整大小)。
当我删除手风琴时,长度仍然是1。当它是0时,我需要调整大小。这可能吗?
$( ".delete_accordion" )
.click(function() {
var parent = $(this).closest('h3');
var head = parent.next('div');
parent.add(head).fadeOut('slow',function(){$(this).remove();});
//length always returns 1 in the function even though it has been removed above.
//perhaps there is an event or method I can intercept on delete?
var parentHasClass = parent.hasClass("accordion");
var isempty = ($("#accordion").length == 0);
alert(isempty);
if(parentHasClass == "true"){
if( isempty ){
myLayout.sizePane("west", 100);
}
}
});
I have the following code to delete a dynamically generated ui-accordion. When the delete occurs (which works) I need to find out if the accordion container which is a div is empty. So if the user deletes the accordion and the container div is now empty I need to resize the containing div (the div is ui.layout pane which I need to resize automatically for the user when the conainter is empty).
When I delete the accorion the length is still 1. I need to resize when it is 0. Is this possible?
$( ".delete_accordion" )
.click(function() {
var parent = $(this).closest('h3');
var head = parent.next('div');
parent.add(head).fadeOut('slow',function(){$(this).remove();});
//length always returns 1 in the function even though it has been removed above.
//perhaps there is an event or method I can intercept on delete?
var parentHasClass = parent.hasClass("accordion");
var isempty = ($("#accordion").length == 0);
alert(isempty);
if(parentHasClass == "true"){
if( isempty ){
myLayout.sizePane("west", 100);
}
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$(this).remove()
直到 fadeOut 完成后才会被调用,因此从技术上讲,长度仍然 === 1。您可以通过将其余的删除逻辑放入淡出回调:
The
$(this).remove()
is not called until after the fadeOut completes, so technically the length still does === 1.You can fix this by putting the rest of your delete logic in the fadeOut callback: