2016-02-10 104 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

没问题队友:) –