1

サブメニューを含む垂直メニューバーがあります。9 ~ 10 個のメニューがあり、各メニューには 3 つのサブメニューが含まれています。

メニュー 1 が開いていて、誰かがメニュー 3 をクリックした場合に必要なもの メニュー 1 を閉じる必要があり、メニュー 3 が開く

 $('#nav li a').click(function(){
    var sds = document.getElementById("dum");
    if(sds == null){
    ;
    }
    var sdss = document.getElementById("dumdiv");
    if(sdss == null){



    }
    if(sdss != null){
            var s = $(this).attr('id');
            var imgid=$("#"+s+" img").attr('id');
            var imgsrc=$("#"+imgid+"").attr('src');
            if(imgsrc=="images/insert.GIF")
            {
                $("#"+imgid+"").attr('src','images/remove.GIF');
                $(this).next().slideDown(400);
                $("#"+s+"").css("background-color","#142878");
            }
            else
            {
                $("#"+imgid+"").attr('src','images/insert.GIF');
                $(this).next().slideUp(400);
                $("#"+s+"").css("background-color","#2d539a");
            }
    }
        });

ここにフィドルがあります

4

3 に答える 3

2

使用する

$('a').next().slideUp(400); 

いずれかのメニューをクリックすると、現在のメニューが閉じて新しいメニューが開きます

これが更新されたフィドルです

于 2014-01-21T09:03:27.257 に答える
1

これを試して:

 $('.count').slideUp(400);     //<----add this line
 $(this).next().slideDown(400);

デモ


アップデート:

これを試して:

if (imgsrc == "images/insert.GIF") {
    $("#" + imgid + "").attr('src', 'images/remove.GIF');
    $('.count').slideUp(400);
    $(this).next().slideDown(400);
    $("#" + s + "").css("background-color", "#142878");
} else {
    $("#" + imgid + "").attr('src', 'images/insert.GIF');
    $('.count').slideUp(400);  //<--------------------add here
    $(this).next().slideDown(400);  //<---------------and here too.
    $("#" + s + "").css("background-color", "#2d539a");
}
于 2014-01-21T09:09:41.400 に答える