javascript - 如何隐藏此 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";
}
解决方案
推荐阅读
- amazon-web-services - Amazon SageMaker 多模型
- angular - NgRx 记忆一个对象
- c - 如何从文件中连续读取()到变量中
- laravel - 如何使用 Laravel 从存储中获取和删除文件?
- gnuplot - gnuplot,后记:没有通过线条样式着色
- aframe - 如何在 oculus 上打开 a-frame 应用程序?
- java - Maven shade 只是将依赖项(3 个中的 2 个)中的一些类着色到最终 jar
- angular - 错误 TS2351:此表达式不可构造
- python-3.x - 如何正确地使这个嵌套的for循环函数
- vue.js - 移动标签时图标颜色改变 - vuej.s