Jquery:编辑表行在新行上不起作用
我正在使用jQuery添加或编辑表上的行。如果我试图编辑一行已经在这里,它的工作,但如果我添加一个新行编辑不工作 我的脚本:Jquery:编辑表行在新行上不起作用,jquery,html-table,row,Jquery,Html Table,Row,我正在使用jQuery添加或编辑表上的行。如果我试图编辑一行已经在这里,它的工作,但如果我添加一个新行编辑不工作 我的脚本: //Add a row $("#btnadd").click(function(){ $('.table tr:last').after('<tr>' + "<td>Name</td>"+ '</tr>'); }); //Edit a row (took from a tutorial) $(funct
//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");
});
});
});
//添加一行
$(“#btnadd”)。单击(函数(){
$('.table tr:last')。在(''+
“姓名”+
'');
});
//编辑行(取自教程)
$(函数(){
$(“td”).dblclick(函数(){
var OriginalContent=$(this.text();
$(this.addClass(“cellEditing”);
$(this.html(“”);
$(this.children().first().focus();
$(this).children().first().keypress(函数(e){
如果(e.which==13){
var newContent=$(this.val();
$(this).parent().text(newContent);
$(this.parent().removeClass(“cellEditing”);
}
});
$(this.children().first().blur(function()){
$(this.parent().text(原始内容);
$(this.parent().removeClass(“cellEditing”);
});
});
});
我对Jquery很陌生,所以我很确定我遗漏了一些明显的东西。
$('table')。在('click','tr',function()上{
$(this.css('color','green');
});
$('button')。在('click',function()上{
var newRow=$('NewRow29');
$('table').append(newRow);
});代码>
吉尔
史密斯
50
前夕
杰克逊
94
添加
你说得对,我忘了“}”);”。谢谢你的回答,但它不起作用:当我只想编辑一行时,使用$('table')可以编辑整个表。