dousui7410 2016-08-21 13:45
浏览 52

在php中结合使用jquery来显示从数据库中获取的可折叠列表

The following program is supposed to display the subjects and subcategory in collapsible list order.

But the collapsible list is applied for the first entry only. The rest of the items appear static. They dont collapse. Why??????????

<html><head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>

<?php
$con = mysqli_connect("localhost","root","","test");
$sql="select * from subject";
$res_subject=mysqli_query($con,$sql);

while($row=mysqli_fetch_array($res_subject))
{
?>

<UL id="subj_tree">
    <LI><span> <?php  echo $row['sub_name'];?> </span>
        <UL>
        <?php
        $sql="select * from sub_categry where sub_id=".$row['sub_id'];
        $res_sub_cat=mysqli_query($con,$sql);
        while($val=mysqli_fetch_array($res_sub_cat))
        {       
        ?>   <LI><span> <?php echo $val['sub_cat_name']; ?> </span></LI>

        <?php } ?>
    </UL>

</LI>
</UL>
<?php
}
?>
 </html>
      <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
   <script type="text/javascript">
      $(function(){
      $('#subj_tree').find('UL').hide();
      $('#subj_tree').find('SPAN').click(function(e){
        $(this).parent().children('UL').toggle();

  });

  });

mysql db is like as follow:

sub_categry: sub_cat_id, sub_cat_type, sub_id (foreign key subject.sub_id)
subject: sub_id, sub_name.

  • 写回答

3条回答 默认 最新

  • douyu53265 2016-08-21 13:57
    关注

    The jQuery find() method only gives you the first element that matches the selector. If you want all the tags under #subj_tree to be hidden, you would have to use

    $('#subj_tree ul').hide();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值