打开一个盒子,关闭所有打开的盒子

时间:2009-09-28 12:51:51

标签: jquery

我有以下(显然我不能这样做!)

function dropBox() {
    $("#reportWrapper a").bind("click", function(){
        $("#reportWrapper a").each(function(i){
            $(this).animate({
                        height: '20px'
            }, 1000);                               
        });
        $(this).parents("div:eq(0)").animate({
            height: '100px'
        }, 1000);
    });
}

我想要的是打开一个被点击并关闭所有打开的。盒子打开盒子,其他人不要关闭。任何帮助非常感谢。 此致

3 个答案:

答案 0 :(得分:0)

如果以将display属性更改为none的方式关闭它们,则可以使用jQuery :visible选择器选择所有其他打开的属性。

答案 1 :(得分:0)

能否知道为什么这不起作用?

function dropBox() {
    $("#reportWrapper a").bind("click", function(){
        var clicked = $(this);
        $("#reportWrapper a").each(function(){  
            if( clicked.attr("name") != $(this).attr("name") )
            {
                $(this).animate({
                    height: '20px'
                }, 1000);
            }
            else
            {
                clicked.parents("div:eq(0)").animate({
                    height: '100px'
                }, 1000);
            }
        });
    });
}

然而,单击框会打开,但打开的那个框不会关闭

function dropBox() {
    $("#reportWrapper a").bind("click", function(){
        var clicked = $(this);
        $("#reportWrapper a").each(function(){  
            if( clicked.attr("name") !== $(this).attr("name") )
            {
                alert("this: " + $(this).attr("name") + "clicked: " + clicked.attr("name"));
                $(this).animate({
                    height: '20px'
                }, 1000);
            }
            else
            {
                clicked.parents("div:eq(0)").animate({
                    height: '100px'
                }, 1000);
            }
        });
    });
}

在上面,提醒每个人除了那个点击的人之外如此重要

该死的......只是怀疑它

答案 2 :(得分:0)

function dropBox() {
    $("#reportWrapper a").bind("click", function(){
            var clicked = $(this);
            $("#reportWrapper a").each(function(){  
                    if( clicked.attr("name") !== $(this).attr("name") )
                    {
                            $(this).parents("div:eq(0)").animate({
                                    height: '20px'
                            }, 1000);
                    }
                    else
                    {
                            clicked.parents("div:eq(0)").animate({
                                    height: '100px'
                            }, 1000);
                    }
            });
    });

}

务!

相关问题