以下代碼可以編輯row.but當我嘗試編輯另一行時,第一次單擊的行仍處於可編輯狀態,以禁用該行嗎?根據用戶選擇編輯行
$("#tableid").on("click", "tr", function() {
$(this).find('td').each(function() {
var matter = $(this).text();
if (matter != "") {
$(this).parents('tr').css('background-color', 'red');
$(this).addClass("editclass");
$(this).html("<input type='text' value='" + matter + "'/>");
$(this).children().first().focus();
$(this).children().first().keypress(function (e) {
if (e.which == 13) {
$(this).parents("tr").css("background-color", "white");
var newvalue = $(this).val();
$(this).parent().text(newvalue);
$(this).removeClass("editclass");
}
});
}
});
$(this).children().first().blur(function() {
$(this).parent().text(matter);
$(this).removeClass("editclass");
});
return false;
});
一個的jsfiddle會幫助別人幫你 – smerny