2017-06-07 55 views
0

我有一個CRUD從數據庫加載表,我希望表格行可編輯通過轉換表單元格輸入字段保存單元格文本作爲輸入值。我正在使用jQuery。 到目前爲止,我可以在標籤內添加輸入字段。但是來自所有單元的數據成​​爲每個輸入的值,而不是變成其各自輸入字段的值。這裏是我的代碼更改表格單元格的輸入值與jquery

$("#parEdit").click(function(){ 
$(this).text("Update"); 
$(this).closest('tr').children().wrapInner('<input type="text" value = ' + $('td').text() + '></input>'); 
    }) 

表 ID |名稱|位置|商標|編輯|

1 |艾哈邁德| 6th | 525 |編輯按鈕|

按下編輯按鈕後的輸出是這樣的

ID |名稱|位置|商標|編輯|

1Ahmad6th525 | 1Ahmad6th525 | 1Ahmad6th525 | 1Ahmad6th525 |更新按鈕|

回答

0

您需要將包裝應用到每個td,您的原始代碼插入每個t​​d文本。

$("#parEdit").click(function(){ 
    $(this).text("Update"); 
    $(this).closest('tr').children().each(function(){ 
     $(this).wrapInner('<input type="text" value = ' + $(this).text() + '></input>'); 
    }); 
}); 
+0

您遺漏了點擊函數的結束標記。感謝您的幫助 – rakibulmuhajir

+0

糟糕!非常感謝 –

相關問題