用jquery&更新列表阿贾克斯 [英] update list with jquery & ajax
问题描述
我用php& jQuery,显示数据库中的每一行.
i make a list with php & jquery which shows every row in my database.
我要向此列表添加一个更新按钮.当用户单击一行时,该行将展开,并且该按钮将变为可见.并且该行上的文本将进入文本框.
i want to add this list an update button. when user clicks on a row, the row will expand and the button will become visible. and the text on that row will go in a textbox.
我的问题是,当用户单击该行中的按钮时,如何更新文本?首先,我想我可以在每一行中放置一个表格..但是我认为这是一个糟糕的解决方案.
and my question is, how can i update the text when user click on the button in that row? first i thought, i could put a form in every row.. but i think that's a terrible solution.
您能为我推荐一个我想做的事的例子或资料吗?
can you suggest me an example or source for what i want to do?
推荐答案
询问代码的问题必须显示您尝试过的代码.由于您没有提供任何代码,因此我将给出一个高级答案:
Questions asking for code must show the code you've tried. Since you didn't give any code, I'll give a high-level answer:
- 将事件处理程序附加到按钮(或可能实际上附加到表并使用委托).
- 在事件处理程序中,使用jQuery遍历函数查找按钮所属的行.
- 一旦您有对该行的引用,请使用jQuery遍历函数在该行中找到
input
. - 获取值并使用ajax更新数据库.
- Attach an event handler to the button (or probably actually to the table and use delegation).
- In the the event handler, use jQuery traversal functions to find the row to which the button belongs.
- Once you have a reference to the row, use jQuery traversal functions to find the
input
s in the row. - Get the values and use ajax to update the database.
这篇关于用jquery&更新列表阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!