Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有带有行的表格,当我单击添加按钮时,灯箱会显示添加行的表单。
现在我想将新添加的行显示到表中,我有两个选项
刷新整个表格,以便所有像“编辑/删除”这样的小按钮也被添加到行中
只添加新行。这很好,但是我必须在模板中添加编辑/删除逻辑并将事件附加到它。
我应该走哪条路?
您应该使用.delegate或.on不将事件附加到表中的所有小按钮。然后您不需要在每次添加行时附加事件。就像是
.delegate
.on
$("#table_id").on("click","button.edit",function(){ //edit the row }).on("click","button.delete",function(){ //delete the row });
看看jquery .on()