duannaxin9975 2014-06-19 03:37
浏览 308
已采纳

如何更新HTML中特定表行的数据?

Since the <form> can not inside <tr>, I can not assign the form for each row. And at the end I have create a from like this

<form>
<table>
<tr><td><input name="my_product_name"></td><td><button type="submit"></td></tr>
<tr><td><input name="my_product_name"></td><td><button type="submit"></td></tr>
</table>
</form>

So, it seems when I submit data it submit every input, how can I send only a specific row? Thanks

  • 写回答

6条回答 默认 最新

  • douju6850 2014-06-19 03:48
    关注

    Since forms send all the values, (since your using <button>), you could assign each row a key that corresponds to that row. Then use that in the textbox. Note: Textbox values must be an array structure, so that particular key from the submit update can be used (kinda like filtering). Consider this example:

    <?php
    
    if(isset($_POST['update'])) {
        $product_key = $_POST['update'];
        $product_name = $_POST['my_product_name'][$product_key];
        echo $product_name;
        // this should correspond to that same textbox row that you selected
    }
    
    ?>
    
    <form method="POST" action="">
        <table>
            <tr>
                <td><input type="text" name="my_product_name[1]"></td>
                <td><button name="update" type="submit" value="1">Update</button></td>
            </tr>
            <tr>
                <td><input type="text" name="my_product_name[2]"></td>
                <td><button name="update" type="submit" value="2">Update</button></td>
            </tr>
        </table>
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了