2011-08-13 32 views
1

如何使用jquery創建編輯對話框?假設我有一個充滿數據的html表格,如果我點擊一行上的按鈕,它會將該行中的數據顯示在jquery對話框中。在php上使用jquery對話框編輯數據

我能夠創建一個對話框來添加數據和刪除數據,但編輯數據和填充jquery上的文本框,我真的沒有想法。

回答

1

你可以有一個編輯按鈕,在每一行

<input type="button" calss="edit" value="Edit" /> 

的最後一個單元格在這個按鈕的點擊獲得該行的所有單元格數據,並把它傳遞給對話框。

$("input.each").click(function(){ 

    var tr = $(this).closes("tr"); 
    var data = []; 
    tr.find("td:not(:last)").each(function(){ 
    data.push($(this).text()); 
    }); 

    //Here open the dialog box which will have the required fields and using the above data array populate the data fields as required 

    //Lets say the first column in the table is for "Name" 
    //You can populate the input "Name" field in the dialog box as. 
    $("input[name=Name]").val(data[0]); 

    //Similarly populate all the data fields using data array 

}); 

對話框也會對點擊其中將更新當前行的單元格與編輯數據的Save按鈕。

0

我想你應該在表格的每一行上都有一個id,以便於識別它。然後你可以從服務器獲取數據。

相關問題