2011-11-28 185 views
0

我有一些數據庫記錄顯示在表格行和列中。 我用純文本顯示這些信息。但是我想在用戶點擊它們時將它們更改爲文本框,並在光標模糊時更新內容。 我希望我能說出我的意思。將文本更改爲文本框後更新純文本

有人幫我嗎?

+0

這將是有益的,如果你能告訴我們一些代碼,也許嘗試你做?另外你使用什麼語言進行服務器端編碼,以便我們可以指出你有用的資源? –

+0

@Mhamhammad嘗試發佈一些代碼,它很難理解你想要什麼,也許代碼會幫助我們幫助你。 – Iznogood

回答

0

要打開一個表格單元格中的內容爲測試輸入:

//bind event handler to click event for all table cells 
$('td').on('click', function() { 

    //cache this table cell in a variable 
    var $table_cell = $(this); 

    //add a text input with the text of this table cell, 
    //then select that text input, focus it (so the user doesn't have to click on the text box to gain focus), 
    //then add an event handler to the text input for the blur event 
    $table_cell.html('<input type="text" value="' + $table_cell.text() + '" />').children('input').focus().bind('blur', function() { 

     //run your code to update the text within this <td> element 

     //sent a POST request to your server-side script with the value of the text-input 
     $.post('path_to/server/script.php', $(this).serialize(), function (response) { 

      //here you get the response from the server and you can update the table cell 
      //if the response from the server is the new text for the cell then you can do this... 
      $table_cell.text(response); 
     }); 
    }); 
});