首页 > 解决方案 > 如何隐藏此 jquery 代码的加载更多按钮

问题描述

我正在尝试建立一个网站,但我对 jquery 的东西很陌生,我在我的网站中添加了 jquery 加载更多评论

我的问题是,我有一个加载更多按钮,它按照我的预期工作,但是当所有数据都加载或没有评论时,我似乎无法让加载按钮变为隐藏

//jquery脚本

<script>
$(document).ready(function() {
  var commentCount = 20;
  var qidNow = "<?php echo $qid; ?>";
  $("button").click(function() {
    commentCount = commentCount + 20;
    $("#comments").load("includes/load-comments.inc.php", {
      commentNewCount: commentCount,
      qid: qidNow
    });
  });
});

//加载评论页面

<?PHP
require 'dbh.inc.php';
include 'function.inc.php';

$commentNewCount = $_POST["commentNewCount"];
$qid = $_POST["qid"];
$count = 0;



  $sqlComment = "SELECT comment, commentTime, commenterId FROM comments WHERE commentOn = ?
   LIMIT ?";

  $stmtComment = mysqli_stmt_init($conn);

  if (!mysqli_stmt_prepare($stmtComment, $sqlComment)) {
    header("Location: ../viewtopic.php?error=sqlerror4");
    exit();
  } else {
    //bind parameter to the placeholder
    mysqli_stmt_bind_param($stmtComment, "ii", $qid, $commentNewCount);
    //run parameter inside database
    mysqli_stmt_execute($stmtComment);
    $commentData = mysqli_stmt_get_result($stmtComment);
  }

  if (mysqli_num_rows($commentData) > 0) {
    while ($row = mysqli_fetch_assoc($commentData)) {
      $count++;
      echo "<div class='individualComment'>";
      echo "<div class='commentCount'> คอมเม้นที่" . $count . "</div>";
      echo "<div class='actualComment'>" . $row['comment'] . "</div>";
      echo "<div class='commentDateBx'>" . dateReformat($row['commentTime']) . "</div>";
      echo "<div class='commenterIdBx'>ID :" . $row['commenterId'] . "</div>";
      echo "</div>";
    }
 }else {
    echo "There is no comment yet";
  }

标签: javascriptphpjquerycss

解决方案


推荐阅读