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条)

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?