如何将HTML表格的内容作为表单数据传递给POST? [英] how to pass contents of an html table as form data on a POST?
问题描述
我有一个< select>
组和一个< input type =buttonvalue =Add Selected >
将选定的群组添加到< table>
值。
I have a list of groups in a <select>
and a <input type="button" value="Add Selected">
to add the selected group to a <table>
of values.
已添加的组列表显示在< table>
中,每当点击添加选定按钮时,javascript会动态添加行。表中的每一行都有一个删除链接,用于从表格中删除项目。
The list of groups that's been added is displayed in a <table>
, rows are dynamically added by javascript on each click of the "Add Selected" button. Each row in the table has a "remove" link that removes the item from the table.
一切正常,除了现在我想将表格内容一个URL,我不知道如何做到这一点。
Everything works fine, except now I want to POST the contents of the table to a URL, and I'm not sure how to do this.
我应该为表中的每一行添加一个隐藏字段吗?或者有更好的方法来做到这一点?
Should I add an hidden field for each row in the table? Or is there a better way to do this?
任何建议都非常感谢!
Rob
推荐答案
将表格包裹在表单中,并将要发布但未显示给用户的数据隐藏在输入中
Wrap your table in a form and put the data you want to post but not display to the user in hidden inputs
<form method="post" action="">
<!-- your table -->
<input type="hidden" name="name" value="your value"/>
<button type="submit">Post</button>
</form>
这篇关于如何将HTML表格的内容作为表单数据传递给POST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!