2009-09-28 132 views
0

我有以下(這很明顯,我不能這樣做!)打開一個盒子,關閉所有打開的

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); 
    }); 
} 

我要的是打開一個被點擊並關閉所有打開的。盒子打開盒子,其他人不關閉。任何幫助非常感謝。 問候

+0

你可以把一部分HTML代碼來幫助你嗎? – 2009-09-28 13:29:36

回答

0

如果在該display屬性更改爲none的方式關閉它們,那麼你可以使用jQuery的:visible選擇器選擇打開的所有其他人。

+0

對不起,即時通訊新的jQuery(PHP的人)你可以精心策劃一些? – 2009-09-28 13:01:35

+0

can yoiu是通過CSS屬性選擇一個元素?即element.css.height.200px? – 2009-09-28 13:02:52

0

可以enyone看到爲什麼這不工作?

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); 
      } 
     }); 
    }); 
} 

以上,提醒大家除了那個那點擊這樣的IM難倒

該死...只是sussed它

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); 
        } 
      }); 
    }); 

}

作品!

相關問題