2011-11-01 88 views
3

我想解決一個隱藏/顯示功能根據,如果div的隱藏或不。我的代碼如下所示:slideToggle,隱藏或可見,如果語句

//postInbox/outbox/savedbox show all/hide all 
$('.postBoxShowAll').click(function(){ 
    $('.postBoxContent').slideToggle('fast', function(){ 
     if($(this).is(':hidden')){ 
      $('.postBoxShowAll').html('Show all'); 
     }else{ 
      $('.postBoxShowAll').html('Hide all'); 
     } 
    }); 
}); 
// 

* UPDATE *

這工作:

//postInbox/outbox/savedbox show all/hide all 
$('.postBoxShowAll').click(function(){ 
    $('.postBoxContent').slideToggle('fast', function(){ 
     if($('.postBoxContent').is(':visible')){ 
      $('.postBoxShowAll').html('Hide all'); 
     }else{ 
      $('.postBoxShowAll').html('Show all'); 
     } 
    }); 
}); 
// 

但由於某些原因,它不會更改文本。它滑得很好。怎麼來的?

+0

這對我的作品。 http://jsfiddle.net/Quincy/FYShk/ – Quincy

+0

我真的不明白爲什麼這不適合我。但是我的問題中的更新適用於我。 – skolind

+0

您使用的是哪個版本的jQuery? – Quincy

回答

7

,可以試試這個

$('.postBoxShowAll').click(function() { 
    $('.postBoxContent').slideToggle('fast', function() { 
     if ($('.postBoxContent').is(':hidden')) { 
      $('.postBoxShowAll').html('Show all'); 
     } else { 
      $('.postBoxShowAll').html('Hide all'); 
     } 
    }); 
}); 
+0

現在正在工作。我只是做了一個:可見而不是隱藏的。我會讓你的答案正確。 – skolind

+0

很高興你找到答案:) –