dongque1646 2015-06-26 06:40
浏览 41
已采纳

jquery而php show hide

<div class="commentfull">
    <?php $comment=m ysqli_query($connect, "SELECT * FROM comment WHERE product = '$p'"); $user=m ysqli_query($connect, "SELECT * FROM user"); $datauser=m ysqli_fetch_assoc($user); while ($datacomment=m ysqli_fetch_assoc($comment)) { ?>
    <div class="commentcontent">
        <div class="commentfill">
            <?php echo $datacomment[ 'comment']; ?>
        </div>
        <ul>
            <li class="commenttime">
                <p>
                    <?php echo $datacomment[ 'time']; ?>
                </p>
            </li>
            <li class="commentreply"><span id="triggerreply">Reply</span></li>
        </ul>
    </div>
    <div class="commentformreply">
        <form method="POST" id="myform" action="<?php echo $base; ?>/config/addcomment.php">
            <input type="hidden" name="p" value="<?php echo $p; ?>" />
            <textarea class="commentarea" name="comment" placeholder="Your comment"></textarea><span class="commentclose">cancel</span>
        </form>
    </div>
    <?php } ?>

jquery :

$("#triggerreply").click(function() {
    $(".commentformreply").slideDown("medium");
});
$(".commentclose").click(function() {
    $(".commentformreply").slideUp("medium");
});

css :

.commentformreply {display:none; }

so, when i clicked 'reply' its show every commentformreply, i just want one of them appearing on its place where i clicked, how to doing this?

  • 写回答

2条回答 默认 最新

  • dougu0824 2015-06-26 06:43
    关注

    Use closest() to select the parent .commentcontent element and then with next(), select the next div (which is .commentformreply element):

    NOTE

    As KAD said, you must not produce more that one element with the same id. Instead, add a class (that's what they are for!)

    $(".triggerreply").click(function(){
        $(this).closest('.commentcontent').next().slideDown("medium");
    });
    $(".commentclose").click(function(){
        $(this).closest('.commentformreply').slideUp("medium");   
    });
    

    EXAMPLE (WORKING)

    Take a look at the following example. It works for multiple blocks of divs.

    $(".triggerreply").click(function(){
        $(this).closest('.commentcontent').next().slideDown("medium");
    });
    $(".commentclose").click(function(){
        $(this).closest('.commentformreply').slideUp("medium");   
    });
    .commentformreply { display:none }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <div class="commentfull">    
            <div class="commentcontent">
                <div class="commentfill">Comment</div>
                <ul>
                    <li class="commenttime"><p>Time</p></li>
                    <li class="commentreply"><span class="triggerreply">Reply</span></li>
                </ul>
            </div>
            <div class="commentformreply">
                <form method="POST" id="myform" action="../config/addcomment.php">
                    <input type="hidden" name="p" value="value>" />
                    <textarea class="commentarea" name="comment" placeholder="Your comment"></textarea><span class="commentclose">cancel</span>    
                </form>
            </div>
      <div class="commentfull">    
            <div class="commentcontent">
                <div class="commentfill">Comment</div>
                <ul>
                    <li class="commenttime"><p>Time</p></li>
                    <li class="commentreply"><span class="triggerreply">Reply</span></li>
                </ul>
            </div>
            <div class="commentformreply">
                <form method="POST" id="myform" action="../config/addcomment.php">
                    <input type="hidden" name="p" value="value>" />
                    <textarea class="commentarea" name="comment" placeholder="Your comment"></textarea><span class="commentclose">cancel</span>    
                </form>
            </div>
    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b