2011-11-28 84 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); 
     }); 
    }); 
});