gpt4 book ai didi

javascript - 编辑表格行

转载 作者:行者123 更新时间:2023-11-29 07:16:01 24 4
gpt4 key购买 nike

关闭。这个问题需要更多 focused .它目前不接受答案。












想改进这个问题?更新问题,使其仅关注一个问题 editing this post .

5年前关闭。




Improve this question




我有从数据库中获取数据的 html 数据,它的 View 和代码如下所示

看法

enter image description here

代码

<?
$sql="SELECT * from `candidates` ORDER BY id DESC";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{
?>
<tr>
<td>
<? echo $row['first_name']; ?>
</td>
<td>
<? echo $row['last_name']; ?>
</td>
<td >
<? echo $row['email_phoneno']; ?>
</td>
<td >
<button type="submit" name="edit" alt="Edit" value="Edit" class="btn blue">Edit</button>
</td>
</tr>
<?}
}
?>

我希望当用户单击特定行的编辑按钮时,该行的数据应该被更改并且它的 View 应该变成这样,并且代码应该如下所示

新 View

enter image description here

新代码
<form action="insert.php" method="post" enctype="multipart/form-data" >
<tr>
<td>
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="First Name" name="first_name" />
</td>
<td>
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Last Name" name="last_name" />
</td>
<td >
<input class="form-control placeholder-no-fix" type="text" autocomplete="off" placeholder="Email/PhoneNo" name="email_phoneno" />
</td>
<td>
<button type="submit" name="add" alt="Add" value="Add" class="btn blue">Add</button>
</td>
</tr>
</form>

谁能告诉它怎么做

最佳答案

1)在渲染记录列表时添加唯一的行ID

2)为按钮添加onclick

3)在按钮onclick中传递唯一的行id

4)在onclick功能中,借助唯一id,随意修改记录

笔记:

  • 您也可以为 td 提供唯一 ID。
  • 不要忘记增加 id 值。
  • 移除提交按钮,如果还需要提交按钮,请在执行完onclick函数中的逻辑后返回true或false。
    <?php
    $count = 1;
    while($row = mysqli_fetch_assoc($result))
    {
    ?>
    <tr id="uniquetrId+count"> <!-- increase this id for each loop iteration -->
    <td>
    <? echo $row['first_name']; ?>
    </td>
    <td>
    <? echo $row['last_name']; ?>
    </td>
    <td >
    <? echo $row['email_phoneno']; ?>
    </td>
    <td >
    <button type="button" name="edit" alt="Edit" value="Edit" class="btn blue" "write a onclick function and pass the unique trid">Edit</button>
    </td>
    </tr>

    <?php
    $count++;
    }
    ?>
  • 关于javascript - 编辑表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37917190/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com