是否可以在同一个html文档中有多个表单?

时间:2014-06-23 13:03:46

标签: html forms

是否可以使用不同的方法在同一个html文档中使用多个表单(没有任何问题), 例如,该文件分为3个部分 每个部分都有一个表格?

<form id="form1" method="POST">..other elements goes here..</form>
<form id="form2" method="GET">..other elements goes here..</form>
<form id="form3" method="POST">..other elements goes here..</form>

1 个答案:

答案 0 :(得分:0)

页面可以包含无限的表单。对于这种情况,我看到两个主要的解决方案。

<强> 1。使用不同的行动地址
使用不同的网址指示表单标记中的操作属性。

<form id="form1" method="POST" action="/login">..other elements goes here..</form>
<form id="form1" method="POST" action="/signup">..other elements goes here..</form>

<强> 2。使用隐藏字段作为标记
添加一个额外的隐藏值,您的操作可以检查该值以分支您的程序流。

<form id="form1" method="POST">
   <input type="hidden" name="service" value="login" />
   ..other elements goes here..
</form>
<form id="form1" method="POST">
   <input type="hidden" name="service" value="signup" />
   ..other elements goes here..
</form>
相关问题