我有一个垂直菜单栏,里面有子菜单。有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");
}
}
});这是小提琴
发布于 2014-01-21 09:09:41
试试这个:
$('.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-21 09:03:27
使用
$('a').next().slideUp(400); 如果单击任何菜单,将关闭当前菜单并打开新菜单。
下面是更新的小提琴
发布于 2014-01-21 09:04:11
将此添加到代码的开头:
$('#nav li a').click(function(){
$(this).closest('li').siblings('li').find('.count').slideUp();
// Rest of the code here最新演示
https://stackoverflow.com/questions/21253306
复制相似问题