2012-01-21 265 views
-5

我试图写一个if/else语句,将隐藏我.thumb<div> S中的“约”或在单击“联系人”链接时。我希望所有的.thumb<div>都能向上滑动。if/else语句

http://dl.dropbox.com/u/14080718/Final/UITabs15.html

我没有太多的经验,写的if/else statementsI似乎无法找出正确的语法任何帮助,您可以给将不胜感激。

 $(function(){ 
    $('.thumb').hide(); 

    $('.subnav').click(function(){ 
     var $menuelement = $('.thumb').eq($(this).closest("li").index());//find the matching nth element in the menu 
     if($menuelement.hasClass('active')){//if clicked element is already expanded 

      $menuelement.removeClass('active').slideUp();//remove the active class and hide it 

     } else {//otherwise,clicked element is not already expanded... 

     if ($('.active').length>0) {//...but another element is expanded 
      $('.active').removeClass('active').slideUp(function(){ 
       $menuelement.addClass('active').slideDown();//add the active class and show it 
      }); 

      } else {//another element is not expanded 

      $menuelement.addClass('active').slideDown();//add the active class and show it 

      } 
     } 
    }); 

    }); 
+7

请将您的源代码发布到问题中! – deceze

+1

你可以添加一些你试过的代码吗? – ThinkingStiff

+0

jQuery不是一种语言。 – Ryan

回答

0

我不能尝试这个,因为它有点孤立,但尝试以下(或至少下面的想法)。我很困惑,因为你的链接实际上并没有包括你发布的代码。如果您仍然遇到问题,请尝试在代码中张贴jsfiddle。您的($('.active').length> 0)语句不需要> 0部分 - 所有非零长度将返回true。

$(function(){ 
     $('.thumb').hide(); 
     $('.subnav').click(function(){ 
      var menuelement = $('.thumb').eq($(this).closest("li").index());//find the matching nth element in the menu 
      $(menuelement).toggleClass('active').slideToggle(); 
      $('.active').not(menuelement).removeClass('active').slideUp(); 
     }); 
});