weixin_33739646 2015-11-21 05:42 采纳率: 0%
浏览 127

HTML中的可扩展表格视图

I am building a dynamic table that fetches and displays data from database, the structure of table looks like this

<table class="table" id="report">
  <thead>
    <tr>
      <th>Title</th>
      <th>Skill</th>
      <th>Area</th>
    </tr>
  </thead>

  <tbody>
    <?
      $sql="SELECT * from tablename ";
      $result= mysqli_query($con, $sql);
      if(mysqli_num_rows($result)>0) {
        while($row = mysqli_fetch_assoc($result)) {
          <tr>
            <td><? echo $title; ?></td>
            <td><? echo $skill; ?></td>
            <td><? echo $area; ?></td>
          </tr>
        }
      }
  </tbody>
</table>

I wish that when a user clicks on title a view should expand and then on another click it should collapse.

I built a static table in jsfiddle and it was working fine, but when I tried to merge the code with my above table it is not working. Can anyone please tell where I went wrong?

  • 写回答

1条回答 默认 最新

  • weixin_33691598 2015-11-21 06:11
    关注

    Try this JS Fiddle and hopefully it'll work, I added the dummy text inside that td and on click on the td that toggles the visibility of child div .hidden

    $(document).ready(function () {
        $('.expandable').on('click', function(){
            $(this).children('.hidden').toggle();
        });
    });
    .hidden {
        display:none;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <table id="report" border="1" style="width:100%" >
        <tr>
            <th> First </th>
            <th> Second </th>
            <th> Third </th>
        </tr>
    
        <tr>
             <td class="expandable">1st title
                <div class="hidden">dummy text 1
                    <br>dummy text 1
                    <br>dummy text 1
                    <br>
                </div>
            </td>
             <td>1</td>
             <td>1</td>
        </tr> 
        <tr>
             <td class="expandable">2st title
                <div class="hidden">dummy text 2
                    <br>dummy text 2
                    <br>dummy text 2
                    <br>
                </div>
            </td>
             <td>2</td>
             <td>2</td>
        </tr>
    </table>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?