简体   繁体   English

单击时使表扩展

[英]Make table expended when clicked

I would like to know how to insert a div or even a number of table rows under a row in a table. 我想知道如何在一个表的一行下插入一个div或什至多个表行。

My code: 我的代码:

<div class="panel-body">
   <form method="POST" action="#re-order">
  <table id="menu" class="table">
        <thead>
          <tr>
            <th>Menu</th>
            <th style="width:50px !important;">Re-order</th>
            <th style="width:50px !important;"></th>
         </tr>
        </thead>
        <tbody>
         <?php
         $a = 0;
         foreach($menus as $menu){
         ?>
          <tr id="<?=$menu['_id'];?>">
            <td><?=$menu['title'];?></td>
            <input type="hidden" name="menu[<?=$a;?>][id]" value="<?=$menu['_id'];?>">
            <td><input type="text" maxlength="2" class="form-control input-sm" value="<?php if(!empty($menu['order'])){ print $menu['order'];}?>" name="menu[<?=$a;?>][order]"></td>
            <td><button type="button" onclick="deletemenu('<?=$menu['_id'];?>');" class="btn btn-sm btn-danger">X</button></td>
          </tr>
          <?php
               $a++;
            }
          ?>

        </tbody>
      </table>
      <br>

What I want to do is if a menu as a submenu I want a button to be on the left of it saying show submenus. 我想做的是,如果菜单作为子菜单,我希望按钮位于其左侧,显示显示子菜单。 This will allow the user to re-order the submenu as well as edit and delete a menu item. 这将允许用户重新排序子菜单以及编辑和删除菜单项。

My issue is without upsetting the form we already have I want to insert it below the corresponding menu item, and allow the user to do what they need. 我的问题是不破坏我们已经拥有的表单,我想将其插入相应的菜单项下方,并允许用户执行所需的操作。

I will be able to work out the form issue (as it is bad practice to have a form in a form. I just want to know should I do this (best practice?) and if so how would I insert the rows. 我将能够解决表单问题(因为在表单中包含表单是一种不好的做法。我只想知道是否应该这样做(最佳做法?),如果可以的话,我将如何插入行。

Option 2) would be a simple lightbox idea or a re-feash of the menu page and only load the submenu. 选项2)是一个简单的灯箱创意,或者是菜单页面的重新设置,仅加载子菜单。

You can use the tbody element's insertRow(index) function and rows collection to manipulate and insert rows where necessary. 您可以使用tbody元素的insertRow(index)函数和rows集合在必要时操纵和插入行。

var tbody = document.getElementById('tbody_id');

// replace row_index with tbody.rows.length for bottom of the table
var tr = tbody.insertRow(row_index);

// set properties of tr as you would normally, appending td children as required.
tr.style.backgroundColor = '#cccccc';
tr.style.color = 'white';
tr.appendChild(document.createElement('td'));
tr.appendChild(document.createElement('td'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM