如何使用“form = form_id” html5输入中的属性 [英] How to use "form=form_id" attribute in html5 input

查看:116
本文介绍了如何使用“form = form_id” html5输入中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用html5输入的form属性,如下所述:

I'm trying to use "form" attribute for html5 input as described here:

[1] http://www.w3schools.com/html5/att_input_form.asp

[ 2] http://www.w3schools.com/html5/tryit.asp?filename = tryhtml5_input_form

该属性的描述表明表单属性:
指定一个或多个表单的以空格分隔的id列表element属于

The description of the attribute says that form attribute: "Specifies a space-separated list of id's to one or more forms the element belongs to"

我正在使用W3C的TryIt编辑器中的代码测试这个(上面的链接2)

I'm testing this by using the code below in W3C's TryIt editor (link 2 above)

<form action="demo_form.asp" id="form1">
First name: <input type="text" name="fname" /><br>
<input type="submit" value="Submit" />
</form>

<form action="demo_form.asp" id="form2">
First name: <input type="text" name="fname" /><br>
<input type="submit" value="Submit" />
</form>

Last name: <input type="text" name="lname" form="form1 form2" />

我在form2中提供了string_for_form2,在lname字段中提供了lastname。我得到的输出为:

I supplied "string_for_form2" in form2 and "lastname" in the lname field. I'm getting the output as:

fname=string_for_form2

而不是

fname=string_for_form2&lname=lastname

为什么结果不符合预期的任何想法?我试过Firefox 17和Chrome 23.

Any ideas why the result is not as expected ? I've tried on Firefox 17 and Chrome 23.

谢谢

推荐答案

因为您正在尝试分配两个表单所有者。

Because you're trying to assign two form owners.


默认情况下,与表单关联的元素与其最近的元素相关联祖先表单元素(如下所述),但可以指定一个表单属性来覆盖它。

"A form-associated element is, by default, associated with its nearest ancestor form element (as described below), but may have a form attribute specified to override this."


http://www.w3.org/TR/html5/forms.html#控制和表单关联


此属性只允许标记灵活性,它不会改变以前规范中的表单所有权范例。

This attribute just allows markup flexibility, it doesn't change the form ownership paradigm from the previous spec.

这篇关于如何使用“form = form_id” html5输入中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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