簡體   English   中英

使用javascript單擊“編輯”按鈕時,如何使行可編輯?

[英]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?
            });

單擊“編輯”按鈕時,我想使該行可編輯,該怎么做?

您需要在td內創建輸入字段,然后在要保存它們時使用javascript加載值並存儲它們。 所以你可以做

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

您可以通過添加contenteditable="true"使td可編輯。 參見下面的代碼。

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

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM