2016-02-10 103 views
-2

我使用一些腳本來隱藏全部內容,但我有問題,這隻隱藏我的第一個div在同時。顯示/隱藏帖子ID

腳本:

$('#blah').css({height:'20px', overflow:'hidden'}); 
$('#blah').on('click', function() { 
    var $this = $(this); 
    if ($this.data('open')) { 
     $this.animate({height:'20px'}); 
     $this.data('open', 0); 

    } 
    else { 
     $this.animate({height:'100%'}); 
     $this.data('open', 1); 
    } 
}); 

雖然PHP代碼,只是想表明,從數據庫中的所有行,並從數據庫中的所有結果必須被隱藏而不只是第一個..

PHP代碼:

$fq = mysqli_query("SELECT * FROM `table` ORDER BY time DESC LIMIT"); 
      while($f = mysqli_fetch_array($fq)){ 

      echo " 
       <div id='blah'>$link</div> 
      "; 

} 

我只想要從數據庫中的所有結果被隱藏,可以通過postid,anyhelp ellapsed?

此致

+0

將其更改爲:'$(文件)。在('點擊','div#blah',function(){...'。 – Darren

+1

'...,even even}'; *失敗*。 –

+0

'LIMIT'在做什麼? – chris85

回答

0

選擇通過jQuery使用ID元件僅選擇所述第一 occurence。 如果要選擇多個元素,不使用ID,使用

while($f = mysqli_fetch_array($fq)){ 

      echo " 
       <div class='blah'>$link</div> 
      "; 

} 

在你的腳本:

$('.blah').css({height:'20px', overflow:'hidden'}); 
    $('.blah').on('click', function() { 
     var $this = $(this); 
     if ($this.data('open')) { 
      $this.animate({height:'20px'}); 
      $this.data('open', 0); 

     } 
     else { 
      $this.animate({height:'100%'}); 
      $this.data('open', 1); 
     } 
    }); 
+0

非常感謝它的作品:) –

+0

沒問題的隊友:) –

+0

沒問題隊友:) –