【问题标题】:Reconciling Show/Hide JQuery Script into PHP将显示/隐藏 JQuery 脚本调和到 PHP
【发布时间】:2015-05-29 14:25:12
【问题描述】:

我目前有一些输出查询结果的 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>

关于如何做到这一点有什么建议吗?

【问题讨论】:

    标签: php jquery html function button


    【解决方案1】:

    如果你用 $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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多