Making row editable when hit row edit button

后端 未结 3 574
暗喜
暗喜 2020-12-01 20:19

I\'m new to jQuery and JavaScript. I\'m trying to click on my Edit button in my table and make the entire row editable. For some reason it\'s not working. I think it\'s o

3条回答
  •  爱一瞬间的悲伤
    2020-12-01 20:39

    Try this:

    $('.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);
        }
    });
    

    jsFiddle

提交回复
热议问题