---
title: "HTML 5 form属性支持"
author: "xhuang"
date: "2011-06-23T11:02:02Z"
tags: []
categories: ["Web前端"]
slug: "html-5-form"
draft: false
lastmod: "2011-06-24T15:16:03Z"
id: 1102005
url: "https://xhuang.iteye.com/blog/1102005"
---

```
<form id="contact_form" method="get">
    <p>
        <label for="name">姓名：</label><input type="text" id="name" name="name">
    </p>
    <p>
        <label for="email">邮箱：</label><input type="email" id="email" name="email">
    </p>
    <input type="submit" id="submit" value="发送">
    <a href="html5-new-form-attribute.html" class="reload">重载当前页</a>
</form>
<p>
    评论：<textarea id="comments" name="comment" form="contact_form [空格传多个id，可以被多个form使用]"></textarea>
</p>
```

HTML5中的`form` 属性可以让HTML控件元素孤立在表单之外，然后表单在提交的时候不仅可以提交表单内的控件元素，这个孤立在外的控件元素值也可以一并提交出去

 

转自：[http://www.zhangxinxu.com/wordpress/?p=1715](http://www.zhangxinxu.com/wordpress/?p=1715)

demo： [http://www.zhangxinxu.com/study/201106/html5-new-form-attribute.html](http://www.zhangxinxu.com/study/201106/html5-new-form-attribute.html)

 

 

 

 

```
<form action="demo_form.asp" method="get" id="user_form">
First name:<input type="text" name="fname" />
<input type="submit" />
</form>

<form action="demo_form.asp" method="get" id="user_form_2">
First name:<input type="text" name="fname2" form="user_form" />
<input type="submit" />
</form>
```

 

input\[name="fname2"]元素，定义form属性是user\_form， 但自己被wrap在user\_form\_2中。此时如果点击user\_form中的提交按钮，input\[name="fname2"]元素一并提交，但当点击user\_form\_2中提交按钮，则提交内容为空

 

总结：当input定义了form属性，则不管他在那，或是在form内，或是独立于form，他只是属于form属性指定的form元素！！！

 

注： 好文章，烂笔头，好记忆