使用 javascript 保存动态 html 表中的数据
我将数据从 mysql 表加载到 HTML 表中。然后用户可以添加或删除一行或多行。最后我必须将更改保存到数据库中。所有这些都必须使用 PHP 和 javascript 来完成。
我知道这看起来并不难。事实上,我设法使用 javascript 函数将数据从数据库加载到 HTML 表中,并从中添加或删除行,但我在尝试保存表中的更改时遇到了最困难的情况。考虑到这些行没有 id,因为它们是动态添加的,如何从表中删除特定行?如何访问特定行的数据?
我希望你们能帮助我。这让我抓狂!谢谢你,对我的英语感到抱歉。
I load data from a mysql table into a HTML table. Then the user can add or remove one or more rows. Finally I have to save the changes into the database. All this have to be done using PHP and javascript.
I know this does not seem very hard. In fact, I managed to load data from database into the HTML table and add or remove rows from it, using javascript function but I'm having the hardest time trying to save changes from the table. How can I delete an specific row from the table, considering that these rows don't have id's since they are dynamically added? How can I access data from an specific row?
I hope you guys can help me out. This is driving me nuts! Thank you and sorry for my English.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果动态添加它们,不能给出行 ID 吗?或者也许用 javascript 迭代表?
If you are adding them dynamically can't you give the rows id's? Or maybe iterate through the table with javascript?
如果您不是针对移动或嵌入式平台进行开发,您可能需要考虑利用一些开发良好的库,例如 DataTables和jEditable。
有来自 DataTables 的示例,它使用 jEditable 来允许内联编辑桌子。这可能与您想要的很接近。
DataTables 库允许您的源来自许多不同的地方,例如 DOM、AJAX、JavaScript 数组或服务器端。查看其网站上的示例。
If you are not developing for mobile or embedded platforms, you may want to considering leverage some well-developed libraries, such as DataTables and jEditable.
There is an example from DataTables, which uses jEditable to allow inline editing for the table. That might be something close to what you want.
The DataTables library allows your source to be from a number of different places, e.g. DOM, AJAX, JavaScript arrays or server-side. Have a look at the examples on their website.