简体   繁体   中英

How make the row editable when edit button is clicked using javascript?

$('#dependents-info').on('click', '.btn-edit-dependent', function () {
                var currentTD = $(this).parents('tr').find('td');
                //what code will I put here?
            });

I want to make the row editable when the Edit button is clicked, how can I do that?

You would need to create input fields inside the td then when you want to save them use javascript to load the values and store them. So you could do

 $('#dependents-info').on('click', '.btn-edit-dependent', function () { var currentTD = $(this).parents('tr').find('td'); var newInput = currentTD.appendChild("input"); newInput.setAttribute("id","newInput1"); }); 

You can make the td editable by adding contenteditable="true" . See below code.

        $('#dependents-info').on('click', '.btn-edit-dependent', function () {
            var currentTD = $(this).parents('tr').find('td');
            currentTD.prop("contenteditable","true");
        });

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM