使用codeigniter从html表获取值 [英] Get values from html table using codeigniter

查看:137
本文介绍了使用codeigniter从html表获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从html表中获取值并传递给codeigniter中的控制器?
我将一个数组传递给一个视图。我遍历该数组,并在表中显示其内容,用户可以在其中更改表。例如,添加行或删除一行,但更改值是一种可能性。但是,然后用户通过按下按钮保存来保存数据。

How can I get the values from a html table and pass that to a controller in codeigniter? I'm passing an array to a view. I walk that array and display its content in a table where the user can alter the table. For example, adding a row, or deleting one, but changing values is a possibility too. But then the user saves the data by pressing the button 'save'.

如何从表中获取数据并将其传递给php?

How do i get the data from the table and pass that to php?

推荐答案

当按下保存按钮时,触发一个使用DOM来获取所需值的javascript函数。你选择一个表单元格,然后使用innerhtml来获取它的字符串。在您的单元格上使用唯一的html ID将使这很容易。在数组中收集所有这些数据,并通过Ajax POST请求将它发送给您的PHP。

When the "save" button is pressed you trigger a javascript function that uses the DOM to get at the values you want. You "select" a table cell and then use innerhtml to get the string inside it. Using unique html id's on your cells will make this easy. Collect all this data in an array and "send" it to your PHP via an Ajax POST request.

这是一种方法。另一种方法是使用 Simplehtmldom ,其中使用PHP而不是JS来获取值。这可能更容易/更困难,取决于你的JS是多好,但方法是一样的。 Simplehtmldom使用与jquery非常相似的语法,在这种情况下,你把负载放在服务器而不是客户端。

That's one way of going about it. Another way is to use Simplehtmldom where you use PHP instead of JS to get your values. This may be easier / more difficult depending on how good your JS is, but the methods are the same. Simplehtmldom uses a syntax that's quite similar to jquery's and in this case you put the load on the server instead of the client.

这篇关于使用codeigniter从html表获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆