簡體   English   中英

編輯html表行並使用php將其更新為mysql表

[英]Edit html table row and update It into mysql table using php

我已經使用JQuery動態地在表的每一行上創建了更新按鈕,該按鈕成功地編輯了表,但是我不知道如何調用php函數來更新數據庫,

我用陪審團作為

$(document).ready(function () {
      $('.editbtn').click(function() {
    var $this = $(this);
    var tds = $this.closest('tr').find('td').filter(function() {
        return $(this).find('.editbtn').length === 0;
    });
    if ($this.html() === 'Edit') {
        $this.html('Save');
        tds.prop('contenteditable', true);

    } else {
        $this.html('Edit');
        tds.prop('contenteditable', false);
    }
});

問題:如何將行ID傳遞給jquery,然后進行update.php頁面,我正竭力為您提供幫助,我曾多次在Google上使用它,但無法解決我的問題

我將更喜歡將“編輯”按鈕上的行ID設置為屬性,當您單擊“編輯”時,可以通過此元素選擇ID。 請檢查以下代碼,例如:

//Here 1 is id of row which you want to edit
<button class="editbtn" data-id="1">Edit Row</button>

您可以在editbtn類上單擊獲取ID,如下所示:

$('.editbtn').click(function() {
    let rowId = $(this).data("id");
});

為了保存更新的值,您需要調用ajax或提交表單。 您需要傳遞所有數據,包括行ID,ajax請求中的其他字段值。 我將更喜歡使用Ajax,因為它不會加載您的頁面,並且對於UI而言看起來要好得多。

希望對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM