2013-10-29 108 views
0

所以我有一个表格,我通过它向我的数据库添加条目,我试图使用相同的表格 来更新/编辑数据库中的现有记录。使用表格数据填写表格

我的页面由添加数据的表格和显示现有数据的表格组成。 对于每个条目,现有数据表都有一列编辑,该表使用php动态填充。

这就是我想要的,当用户点击任何行的编辑按钮时,该行中的数据应该自动填充到表单中。

我做了一个的jsfiddle here

JS脚本我曾尝试:

$("#tableID").on("click", ".edit_button", function() { 
    var data = $(this).closest("td").siblings().map(function() { 
     return $(this).text(); 
    }).toArray(); 

    console.log(data); 
}); // the event is not recognized. no action on clicking. 

有相当一些技术,我发现这里计算器,但大多DONOT响应点击事件,否则返回null /空值,是因为表单是动态填充的吗?

我对web开发很新,任何帮助将不胜感激。谢谢!

注:数据库包含超过20+的记录(动态增加),在我的jsfiddle显示只有1,保持代码干净。比较遗憾的是没有CSS样式的:P

+0

你检查控制台的任何错误是有帮助吗?在小提琴中添加jquery js到您的代码 – AmGates

+0

使用您的代码在document.ready() – AmGates

+0

document.ready()中检测按钮点击谢谢!!但数据数组是空的。 – user2529058

回答

0
$("#tableID").on("click", ".edit_button", function() { 
    var data = $(this).closest("td").siblings().map(function() { 
     return $(this).text(); 
    }).toArray(); 

    console.log(data); 
}); 

这样使用可能是

$("#tableID").click(function() { 
    var data = $(this).closest("td").siblings().map(function() { 
     return $(this).text(); 
    }).toArray(); 

    console.log(data); 
});