我正在嘗試隱藏 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>";
}; ?>
uj5u.com熱心網友回復:
您可以將此列的顯示樣式設定為“無”,而不是洗掉該列
(添加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>
uj5u.com熱心網友回復:
您可以嘗試修改editUser()
和deleteUser()
Javascript 方法以接受 userId 引數。它可能也會清理 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 的解決方案,該解決方案可能適用于您現有的代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/468961.html