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 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
  • ¥15 计算决策面并仿真附上结果
  • ¥20 halcon 图像拼接
  • ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错
  • ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥100 求ASMedia ASM1184e & ASM1187e 芯片datasheet/规格书
  • ¥15 求解决扩散模型代码问题
  • ¥15 工创大赛太阳能电动车项目零基础要学什么