gpt4 book ai didi

php - 协调显示/隐藏 JQuery 脚本到 PHP

转载 作者:可可西里 更新时间:2023-10-31 23:39:33 25 4
gpt4 key购买 nike

我目前有一些 php 脚本可以输出查询结果。我想在末尾添加两个按钮来显示/隐藏最后一个元素,但我不确定该怎么做。

以下是我的php脚本:

while($result = mysqli_fetch_array($iname))
{
echo "<b>Event Name:</b> " .$result['EventName'];
echo "<br> ";
echo "<b>Location:</b> ".$result['Location'];
echo "<br>";
//this is where I would like to add my two buttons, that would show the "hidden" content when clicked

这是我用 HTML 脚本编写的内容,我想将其调和到 PHP 输出中:

<!DOCTYPE html>
<html>
<head>
<scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js></script>
<script>
$(document).ready(function(){

$("#hidden").hide();

$("#hide").click(function(){
$("#hidden").hide(500);
});
$("#show").click(function(){
$("#hidden").show(500);
});
});
</script>
</head>
<body>

<button id="show">Show</button>
<button id="hide">Hide</button>

<p id="hidden">

Some Random Text that will be shown when the buttons are clicked

</p>

</body>
</html>

关于如何完成此操作有什么建议吗?

最佳答案

如果使用 $num_rows = mysql_num_rows($result); 获取结果行数怎么样?然后,在循环中放置一个计数器。

    $counter = 1;
$theClass="";
while($result = mysqli_fetch_array($iname))
{

if ($counter == mysql_num_rows($result);){
$theClass="showHide";
}
echo "<div class='$theClass'>";
echo "<b>Event Name:</b> " .$result['EventName'];
echo "<br> ";
echo "<b>Location:</b> ".$result['Location'];
echo "<br>";
echo "</div>

$counter++;
}

然后,将您的 javascript 应用于 class="showHide"的 div

关于php - 协调显示/隐藏 JQuery 脚本到 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30532120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com