简体   繁体   English

“ document.forms不是函数”和“ document.forms(0)”

[英]“document.forms is not a function” with “document.forms(0)”

I am maintaining many old websites and CMS systems at my new job and run into an issue with one. 我在新工作中维护许多旧网站和CMS系统,但遇到一个问题。 The ASP site is using JavaScript and this line stopped working today (or slightly earlier than today): ASP站点正在使用JavaScript,并且此行今天(或今天稍早)停止工作:

document.forms(0)

Console would report Uncaught TypeError: document.forms is not a function . 控制台将报告Uncaught TypeError: document.forms is not a function After Googling, I found that I can replace it with: 谷歌搜索后,我发现可以将其替换为:

document.forms[0]

and continue moving forward, however, this website and files are littered with this reference. 并继续前进,但是,此网站和文件充斥着该参考资料。

Can anyone find explain what might have happen? 谁能找到解释可能发生的情况? Chrome, IE and Firefox are not working, was there an update to browsers or JavaScript? Chrome,IE和Firefox无法正常工作,浏览器或JavaScript是否进行了更新? I can't seem to find document.forms(0) in my searches. 我似乎在搜索中找不到document.forms(0) Odd. 奇。

I will post the answer that I have thus far and like the comments mention, this is not a standard for all browsers, it will work in IE, but generally nothing else: 我将发布到目前为止的答案,就像评论中提到的那样,这不是所有浏览器的标准,它可以在IE中使用,但通常没有其他功能:

document.forms(0) //IE only

This is the proper way: 这是正确的方法:

document.forms[0] //All browsers (including IE)

I was able to find ONE article (Mozilla developer network) that references the round-brackets ( link ) saying that document.forms(0) is IE-specific ways to access elements and document.forms[0] is the W3C web standards replacements . 我能够找到一篇引用圆括号( link )的文章(Mozilla开发人员网络),其中说document.forms(0)IE-specific ways to access elementsdocument.forms[0]W3C web standards replacements

To confirm, I did some testing with BrowserStack and noticed that all versions of IE were working, nothing else worked except for Chrome version 15 and 16 (first two versions that BrowserStack has on their system for XP ). 为了确认这一点,我对BrowserStack进行了一些测试,发现所有版本的IE都可以正常工作,除了Chrome版本15和16(BrowserStack在其用于XP的系统上拥有的前两个版本)之外,其他所有功能均不起作用。

Use the following code or your website will only be IE compatible: document.forms[0] 使用以下代码,否则您的网站将仅与IE兼容: document.forms[0]

Maybe my Client was always using IE and just switched to Chrome or something else. 也许我的客户一直在使用IE,而只是改用Chrome或其他工具。 I haven't confirmed that yet, more does the site have any time of Analytics. 我尚未确认,该网站在任何时间都可以进行Analytics(分析)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM