代码之家  ›  专栏  ›  技术社区  ›  Just Kroosing

如何隐藏表格行?

  •  1
  • Just Kroosing  · 技术社区  · 3 年前

    我试图隐藏user_id的表行。我只想在表中显示全名、用户名和操作。我试图删除用户id行的代码,但它影响了其他功能,如编辑和删除。

    以下是代码:

    <form method="post" id="editForm"> 
        <table class="table">
            <tbody>
            <tr>
                    <th scope="col">USER ID</th>
                    <th scope="col">FULL NAME</th>
                    <th scope="col">USER NAME</th>
                    <th scope="col">ACTIONS</th>
            </tr>
            
            <?php $a = 0?>
    
            <?php while ($row = mysqli_fetch_array($res)) { 
    
                echo "<tr id=".$a++.">
                    <th scope='row' class='row-data'>".$row['user_id']."</th>
                    <td class='row-data'>".$row['full_name']."</td>
                    <td class='row-data'>".$row['user_name']."</td>
                    <td><input type='button' 
                            value='EDIT'
                               onclick='editUser()'' /></td>
                    <td><input type='button' 
                             value='DELETE' 
                       onclick='deleteUser()' /></td>
                </tr>
            
            </tbody>";
           }; ?>
    
    2 回复  |  直到 3 年前
        1
  •  1
  •   Ken Lee    3 年前

    您可以将此列的显示样式设置为“无”,而不是删除该列

    (添加 style="display:none;" )

    因此(1)改变

    <th scope="col">USER ID</th>
    

    <th scope="col" style="display:none;">USER ID</th>
    

    (2)改变

    <th scope='row' class='row-data'>".$row['user_id']."</th>
    

    <th scope='row' class='row-data' style="display:none;">".$row['user_id']."</th>
    
        2
  •  0
  •   Ervin Å abić    3 年前

    您可以尝试修改 editUser() deleteUser() Javascript方法来接受用户ID参数。它可能会清理JS端的一些代码。不过只是一个建议。那么这个片段可能看起来像这样:

    <form method="post" id="editForm"> 
        <table class="table">
            <tbody>
            <tr>
                    <th scope="col">FULL NAME</th>
                    <th scope="col">USER NAME</th>
                    <th scope="col">ACTIONS</th>
            </tr>
            
            <?php $a = 0?>
    
            <?php while ($row = mysqli_fetch_array($res)) { 
    
                echo "<tr id='".$a++."'>
                    <td class='row-data'>".$row['full_name']."</td>
                    <td class='row-data'>".$row['user_name']."</td>
                    <td><input type='button' 
                            value='EDIT'
                               onclick='editUser(".$row['user_id'].")'' /></td>
                    <td><input type='button' 
                             value='DELETE' 
                       onclick='deleteUser(".$row['user_id'].")' /></td>
                </tr>
            
            </tbody>";
           }; ?>
    

    否则,您可以使用Ken的解决方案,该解决方案可能适用于您现有的代码。