【发布时间】:2015-01-18 14:32:37
【问题描述】:
我正在使用 jQuery 在表格中添加或编辑行。如果我尝试在此处编辑已经存在的行,它可以工作,但如果我添加新行,则编辑不起作用。
我的脚本:
//Add a row
$("#btnadd").click(function(){
$('.table tr:last').after('<tr>' +
"<td>Name</td>"+
'</tr>');
});
//Edit a row (took from a tutorial)
$(function () {
$("td").dblclick(function () {
var OriginalContent = $(this).text();
$(this).addClass("cellEditing");
$(this).html("<input type='text' value='" + OriginalContent + "' />");
$(this).children().first().focus();
$(this).children().first().keypress(function (e) {
if (e.which == 13) {
var newContent = $(this).val();
$(this).parent().text(newContent);
$(this).parent().removeClass("cellEditing");
}
});
$(this).children().first().blur(function(){
$(this).parent().text(OriginalContent);
$(this).parent().removeClass("cellEditing");
});
});
});
我对 Jquery 很陌生,所以我很确定我错过了一些明显的东西。
【问题讨论】:
标签: jquery html-table row