嵌入HTML<表格>在一个更大的< form>中? [英] Embed an HTML <form> within a larger <form>?

查看:111
本文介绍了嵌入HTML<表格>在一个更大的< form>中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < form id =form1> ; 
< input name =val1/>
< form id =form2>
< input name =val2/>
< input type =buttonname =仅提交表格2>
< / form>
< input type =buttonname =Submit Form 1 data including form 2>
< / form>

我需要提交form1的全部内容,但是当我提交form2时,我只想提交数据在form2中(不是所有form1中的内容)。这会起作用吗?

解决方案

您所描述的内容不起作用。



一种解决方法是创建两个不嵌套的表单。您将使用原始父窗体的隐藏输入来复制原始嵌套窗体的输入。然后,在允许表单提交之前,使用Javascript / DOM操作将提交事件挂接到父表单上,将嵌套表单中的值复制到父表单中的隐藏输入中。


$ b 您的表单结构看起来像这样(忽略布局HTML):

 < form id =form1> 
< input name =val1/>
< input name =val2type =hidden/>
< input type =buttonname =Submit Form 1 data including form 2
onsubmit =return copyFromForm2Function()>
< / form>
< form id =form2>
< input name =val2/>
< input type =buttonname =仅提交表格2>
< / form>


I want to have an HTML form embedded in another form like so:

<form id="form1">
  <input name="val1"/>
  <form id="form2">
    <input name="val2"/>
    <input type="button" name="Submit Form 2 ONLY">
  </form>
<input type="button" name="Submit Form 1 data including form 2">
</form>

I need to submit the entirety of form1, but when I submit form2 I only want to submit the data in form2 (not everything in form1.) Will this work?

解决方案

What you have described will not work.

One workaround would be to create two forms that are not nested. You would use hidden inputs for your original parent form that duplicate the inputs from your original nested form. Then use Javascript/DOM manipulation to hook the submit event on your "parent" form, copying the values from the "nested" form into the hidden inputs in the "parent" form before allowing the form to submit.

Your form structure would look something like this (ignoring layout HTML):

<form id="form1">
  <input name="val1"/>
  <input name="val2" type="hidden" />
  <input type="button" name="Submit Form 1 data including form 2" 
         onsubmit="return copyFromForm2Function()">
</form>
<form id="form2">
  <input name="val2"/>
  <input type="button" name="Submit Form 2 ONLY">
</form>

这篇关于嵌入HTML&lt;表格&gt;在一个更大的&lt; form&gt;中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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