【问题标题】:Im displaying results from a php query and want to display each one in a different slide toggle我正在显示来自 php 查询的结果,并希望在不同的幻灯片中显示每个结果
【发布时间】:2013-03-24 21:57:37
【问题描述】:

我有一个显示子信息的切换开关工作,但以下切换不起作用,我不知道如何解决这个问题。我使用了 w3schools 的代码来让它工作,但其他名称似乎并没有滑下来,只是显示它们。请问有什么想法吗?

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
   <script> 
    $(document).ready(function(){
     $("#flip").click(function(){
     $("#panel").slideToggle("slow");
    });
    });
    </script>

    <style type="text/css"> 
     #panel,#flip
   {
     padding:5px;
    text-align:center;
     background-color:#e5eecc;
     border:solid 1px #c3c3c3;
      }
    #panel
    {
    padding:50px;
   display:none;
   }
   </style>

    $connect = mysql_connect("127.0.0.1" , "root" , "") or die ("Couldnt connect to database");
    mysql_select_db("travellerfile") or die ("couldnt find the database");

    $searchsurname = $_POST['Surname'];
    $searchfirstname = $_POST['Firstname'];
    $searchage = $_POST['Age'];

    $query = mysql_query("SELECT * FROM child WHERE Surname like '%$searchsurname%' and Firstname like '%$searchfirstname%' and Age like '%$searchage%'");
    while($row = mysql_fetch_array($query))
    {
    ?>
    <div id="flip"><?php echo $row['Firstname']; ?> <?php echo $row['Surname']; ?></div>
    <div id="panel"><?php echo $row['DateOfBirth']; ?> <br /> <img src="<?php echo $row['sourcepath']; ?>" width="100px" height="100px"> <form method="post" action="childdetail.php">
                <input name="Button1" type="submit" value="View" /></form>

【问题讨论】:

  • 你已经创建的代码在哪里?
  • _w3schools to get it working_ 嗯.....
  • 我是新的,不知道如何插入代码?
  • 将代码缩进 4 个空格,或发布 jsFiddlePastebin
  • 我上传的代码..它不是整个代码,但它是唯一与 jquery 和 php 相关的代码

标签: php jquery html mysql css


【解决方案1】:

你不能有重复的元素id,我建议你把它们改成类:

<div class="flip"> 
<div class="panel"> 

至于jQuery,你需要知道panelslideToggle在哪个@,根据对应的flip。鉴于您当前的结构,您可以使用以下内容:-

$('.flip').click(function() {
  $(this).next('.panel').slideToggle('slow'); 
});

Here's a simplified example of what you were trying to achieve

【讨论】:

  • 实施你的建议已经把整个事情都拿走了,只是以标准的方式而不是切换开关来显示结果!我非常感谢您的建议,并会尝试任何事情!想把我的头发拉出来,因为我知道它会很简单! ://
  • 记得将所有对#panel#flip 的引用替换为.panel.flip
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-14
  • 2013-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多