元素不出现在 document.forms.elements 中?-6ren"> 元素不出现在 document.forms.elements 中?-前几天我在 Mozilla Developer Network 上阅读document.forms[x].element 集合将不包含 type="image"的输入元素。为什么不?我在 Firefo-6ren">
gpt4 book ai didi

JavaScript:为什么 <input type ="image"> 元素不出现在 document.forms.elements 中?

转载 作者:行者123 更新时间:2023-11-29 23:56:05 25 4
gpt4 key购买 nike

前几天我在 Mozilla Developer Network 上阅读document.forms[x].element 集合将不包含 type="image"的输入元素。为什么不?我在 Firefox 50.1.0 上检查了这个,果然,我在 document.forms.elements 中找不到 input type="image"

我没有卡住或任何东西。我只是想知道为什么会这样(除了 src="" 属性及其显示的图像的存在)。

Mozilla Developer Network状态:

The HTMLFormElement.elements property returns an HTMLFormControlsCollection (HTML 4 HTMLCollection) of all the form controls contained in the FORM element, with the exception of input elements which have a type attribute of image.

WHATWG说:

The elements IDL attribute must return an HTMLFormControlsCollection rooted at the form element, whose filter matches listed elements whose form owner is the form element, with the exception of input elements whose type attribute is in the Image Button state, which must, for historical reasons, be excluded from this particular collection.

World Wide Web Consortium说:

The image button state represents either an image from which a user can select a coordinate and submit the form, or alternatively a button from which the user can submit the form. The element is a button, specifically a submit button.

最佳答案

我已经检查了很多关于此事的资源,并特别找到了这个可以追溯到 1999 年 7 月 15 日的网站:

http://www.alanflavell.org.uk/www/trysub.html

带有 type=image 的 input 元素专门用作图像映射,并包含其他 HTMLFormElement 不具备或不具备的属性和功能。我记得它被用于 map 和其他图形,用户可以在 map 上选择一个特定的点,坐标被传输回服务器及其 cgi 应用程序,然后根据点击的坐标提供内容。在我看来,它是现代浏览器中为数不多的古老遗迹之一,可以被视为僵尸功能。

在 Mozilla 的 Bugzilla 中也可能发现问题,报告此元素的异常行为既不符合图像也不符合输入元素:

https://bugzilla.mozilla.org/show_bug.cgi?id=110595

我无法快速找到 1998 年的 Netscape Navigator 源代码,也不认为其中会有任何有用的评论。我非常确定做出这个决定是因为 IMAGE-input 元素是如此怪异、陌生且与其他元素不同,以至于不值得在任何方向上改变其行为的规范、设计和开发工作。在 JavaScript 核心和 DOM 中将其作为 FORM 元素实现是不值得的。

我发现的一切都得出了这个结论,但要获得充分的证据,我们需要找到做出决定的人,并且是第一个实现导致该规范决定的人。从历史的 Angular 来看,这当然是令人兴奋的。

关于JavaScript:为什么 &lt;input type ="image"> 元素不出现在 document.forms.elements 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41626103/

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