如何组合html表单
我如何组合 2 个 html 表单,
我试图将其组合到不同位置的表单。这样我就可以一次性发布所有数据。
这是一个例如
<form action="actions.php">
<input type="text">
<input type="text">
<input type="submit" name="button" id="button" value="submit" />
</form>
<form>
<input type="text">
<input type="text">
</form>
How would i combined 2 html forms
I am trying to combined to forms that are in different position. so i can post all the data at once.
Here is a eg
<form action="actions.php">
<input type="text">
<input type="text">
<input type="submit" name="button" id="button" value="submit" />
</form>
<form>
<input type="text">
<input type="text">
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
您可以在第二个表单中添加隐藏字段,并在提交之前使用第一个表单值填充这些字段(使用 java 脚本)。
You can add hidden fields in the second form and fill these fields (using java script) with the first form values before submission.
我知道这个问题有多久了,但无论如何,这里是使用 HTML5 Form 属性的答案。 (属性而不是标签。)
只需为您的主表单创建一个 id(即 id="main-form")
并在您的其他输入中(不使用其他表单标签)将新的 HTML5 表单属性 (属性不是标签) 与主表单 id 的值(即 form="main-form") .
* 但是 IE 不支持
I know how old this question is, but here is the answer anyway, using HTML5 Form attribute. (an attribute not a tag.)
Just make an id for your main form (i.e. id="main-form")
And in your other inputs (without using another form tag) put the new HTML5 form attribute (an attribute not a tag) with a value of your main form id (i.e. form="main-form").
* However It's not supported in IE
我不知道你的实际要求,但建议和标准做法(据我所知)有一种形式并将元素放入其中..可以将它们放置在 div/table/css 等内部。然后通过使用 javascript 你可以获取控制值。例如:
或者
希望这会给一些想法
I do not know your actual requirement but it is advisable and standard practice(as what I know) to have one form and put the elements into that.. may be position them inside div/table/css etc. Then by using javascript you can get the control values. e.g:
or
hope this will give some idea
不要制作 2 份表格。使用正确的 HTML 元素和 CSS 进行布局。请随意使用 JavaScript 来制作动画并根据需要添加效果。
我所说的适当元素是指您可以执行以下操作:
并使用 CSS 来放置它们。
当然,请根据您的需要调整示例。
Do NOT make 2 forms. Use proper HTML elements and CSS for layout. Feel free to use javascript to animate and add effects as needed.
By proper elements I mean you could do something like:
And use CSS to place them.
Of course, adapt the example to your needs.
如果我没记错的话,你可以在 之间放置一些东西。
If I'm not mistaken, you can put stuff in between the <input> entries in a <form>, if that's what you're worried about. Just make the form span the entire portion of the page which contains the inputs from what are currently two forms, and put the other non-form stuff inside the new <form>.
现在它们结合在一起了。
Now they are combined.
为了发挥作用,您的输入标签需要名称属性。
使用分区和 CSS,如下所示:
CSS 可用于定位表单的每个部分。
另一种选择是使用 javascript,如下所示:
也可以执行相反的操作:
To be useful, your input tags need name attributes.
Use divisions and CSS, like this:
CSS can be used to position each part of your form.
Another option would be to use javascript, like this:
The inverse can also be done:
只需使用一个
form
标签:所有表单数据都将在一次调用中提交(正如您在评论之一中指出的那样)到
actions.php
。请注意,如果任何输入元素上没有任何 ID,此表单(以及您在问题中发布的表单)就不是很有用,因为您会发现在没有 ID 的情况下很难区分这些值。
关于表单的外观 - 您应该使用 CSS 来设置不同元素的样式和位置。
Just use a single
form
tag:All the form data will be submitted in one call (as you indicate is what you want in one of your comments) to
actions.php
.Note that this form (and the ones you posted in your question) are not very useful without any IDs on any of the input elements, as you will find it difficult to tell the values apart without one.
In regards to how the form look - you should use CSS to style and position the different elements.
使用 javascript,您可以获取所有表单元素并将它们全部组合到同一个表单中并同时提交。这就是您正在寻找的吗?
With javascript you can grab all the form elements and combine them all into the same form and submit them at the same time. Is that kind of what you're looking for?
HTML 允许您在表单中包含其他文本和标签。只需这样做:
HTML lets you have other text and tags inside of a form. Just do this: