我想動態更新我的表格行,我應該使用jquery抓取表格單元格的值。問題是抓取的值爲空而不是「標題」。你能否檢查下面的代碼,並幫我找到錯誤。我研究並發現我應該使用text()而不是html(),但仍然無法獲得結果。jquery抓取值爲null,而不是從動態創建的表格的單元格中獲得正確值
$.each(data.results, function(i, res) {
var row = $('<tr>').append(
$('<td>').html(res.id),
$('<td class="title" contenteditable="true">').html(res.title),
$('<td>').html('<a href="#" class="update" name="'+res.id+'">Update</a>')
);
item.append(row);
});
$("#show").html(item);
$("body").on("click", ".update", function() {
var self = this;
var id = $(self).attr("name");
var title = $(self).closest(".title").text(); //cannot grab the value,
...
感謝您的回答。我剛剛以你描述的方式嘗試過,但不幸的是它仍然不起作用。我也試過** var title = $(self).parent()。find(「。title」)。text(); ** – EducateYourself 2014-09-27 12:13:59
@EducateYourself然後你的html輸出有問題 – Exlord 2014-09-27 12:27:39
但是單元格值可以是正確顯示,問題是我無法獲取該值 – EducateYourself 2014-09-27 12:43:03