按帖子 ID 显示/隐藏


Show/hide by post id

>我使用一些脚本来隐藏完整的内容,但我有问题,这只隐藏了我的第一个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);
    }
});

而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 删除,有什么帮助吗?

此致敬意

使用 ID 通过 jQuery 选择元素只会选择第一个匹配项。如果要选择许多元素,请不要使用 ID,请使用 Class

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