gpt4 book ai didi

html - 是否需要 HTML 用户代理以特定顺序提交表单数据?

转载 作者:搜寻专家 更新时间:2023-10-31 08:06:26 26 4
gpt4 key购买 nike

对于给定的 HTML 表单,是否需要用户代理以特定顺序构建提交请求?

我正在查看 HTML 4.0.1 规范,它似乎没有指定“成功控制”成为提交请求的一部分的顺序。 Section 17.13.3 , 处理表单数据, 状态:

When the user submits a form (e.g., by activating a submit button), the user agent processes it as follows.

Step one: Identify the successful controls

Step two: Build a form data set

A form data set is a sequence of control-name/current-value pairs constructed from successful controls

Step three: Encode the form data set

The form data set is then encoded according to the content type specified by the enctype attribute of the FORM element.

Step four: Submit the encoded form data set

在第二步,表单数据集被描述为一个序列,因此它在第三步中编码的顺序大概是固定的。但是,这引出了表单数据集中成功控件的顺序是什么的问题。

例如,给定以下 HTML 表单:

<form action="#" method="GET">
<input type="hidden" name="key1" value="value1" />
<div>
<div>
<input type="hidden" name="key2" value="value2" />
</div>
<input type="hidden" name="key3" value="value3" />
<input type="submit" name="submit" value="Submit" />
</div>
<input type="hidden" name="key5" value="value5" />
</form>

表单数据集是否可以

[ ("key1", "value1"), ("key2", "value2"), ("key3", "value3"), ("submit", "Submit"), ("key5", "value5") ]

(即 DOM 的深度优先搜索);或

[ ("key1", "value1"), ("key5", "value5"), ("key3", "value3"), ("submit", "Submit"), ("key2", "value2") ]

(广度优先搜索);甚至是在随机哈希表中迭代控件名称/当前值对所产生的不确定顺序?

用IE 9和Firefox 9.0.1测试这个表单,似乎都使用了深度优先搜索顺序。可能其他浏览器不一样。问题是这个命令是否在某处规定。

最佳答案

如果你继续第 17.13.4 of the HTML spec ,它声明默认内容类型是 application/x-www-form-urlencoded。该内容类型的部分说:

The control names/values are listed in the order they appear in the document.

这表明深度优先遍历并且似乎与您的浏览器测试一致。

关于html - 是否需要 HTML 用户代理以特定顺序提交表单数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com