Using jQuery to edit individual table cells

前端 未结 10 1972
心在旅途
心在旅途 2020-12-13 08:14

How can I use jQuery to click on a table cell and edit its contents. There is a particular column which contains several paragraphs of data, so if possible, have a pop up wi

相关标签:
10条回答
  • 2020-12-13 08:47

    I use Data tables (a jQuery plugin) as this makes everything so much simpler.

    They also say to use the jEditable plugin with their plugin. Allows for rows to become editable: Link: Editable Table (includes code sample)

    0 讨论(0)
  • 2020-12-13 08:47

    jEditable plugin can help you edit your table in place.

    $(document).ready(function() {
        $('td').editable('http://www.example.com/save.php');
    });
    
    0 讨论(0)
  • 2020-12-13 08:48

    Inkedmn's code not functional as it is but it is the simplest way to do it as an idea: So check out the following working code based on his logic:

    $(function() {
        $('#overlay').hide();
        $('td').click(function(event) {
            var myText = '';
            $('#overlay').show();
            var o = $(this);
            $('#closeLink').click(function(event) {
                event.preventDefault();
                myText = $('#overlay textarea').val();
                $(o).html(myText);
                $(this).parent().hide(500);
            });                  
        });
    });
    
    0 讨论(0)
  • 2020-12-13 08:49

    Try this simple solution:

    $(function () {
        $("td").dblclick(function () {
            var OriginalContent = $(this).text();
    
            var inputNewText = prompt("Enter new content for:", OriginalContent);
    
            if (inputNewText != null) {
                $(this).text(inputNewText)
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题