" document.formName"未定义? [英] "document.formName" is undefined?

查看:156
本文介绍了" document.formName"未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用IIS Express在我的XP系统上本地运行的ASP.NET站点。在Windows服务器上运行该站点的实时版本。

I've got an ASP.NET site running locally on my XP system using IIS Express. There is a live version of the site running on a Windows server.

在网页中,Javascript通常会使用样式 document.formName 引用页面上的表单,其中 formName 是表单的名称。据我所知,这是一个跨浏览器的方法,以及 document.forms.formName document.forms [0] 依此类推。

In the web pages, often the Javascript will reference a form on the page using the style document.formName, where formName is the name of the form. As far as I know, this is a cross-browser method, along with document.forms.formName and document.forms[0] and so forth.

在我的本地开发网站上,引用 document.frm1 (我知道) ,错误的命名实践)错误;它是未定义的。另一方面, document.forms.frm1 工作正常。奇怪的是,这不会发生在服务器上,尽管两个页面都是相同的代码。我用Firebug和IE8和Firefox 6进行了双重检查。

On my local development site, the reference document.frm1 (I know, bad naming practice) errors out; it is undefined. On the other hand, document.forms.frm1 works fine. Strangely, this doesn't occur on the server, although both pages are identical as far as the code goes. I've double checked with Firebug, and in both IE8 and Firefox 6.

另一个奇怪的部分:用Firebug检查, document.frm1 未定义,但 document.frmClose (另一种形式)存在!嗯?!

Another weird part: checking with Firebug, document.frm1 is undefined, but document.frmClose (another form) exists! Huh?!

以前有人经历过这个吗?

Anyone experienced this before?

推荐答案

编辑1

我做了一些实验,发现 id 属性用于 document.forms ,而 name 属性似乎用于 document.formName

I did some experimentation, and found that the id property is used for document.forms, whereas the name property seems to be used for document.formName

http://jsfiddle.net/GVjsv /

原始答案

确保在DOM准备好之前你的javascript没有执行。一种帮助方法是将您的javascript放在页面底部,或者如果您正在使用框架,请确保将代码包装在 ready -type函数中:

Ensure that your javascript is not executing before DOM is ready. One way to help is to put your javascript at the bottom of the page, or if you're using a framework be sure to wrap the code in a ready-type function:

jQuery: http://api.jquery.com / ready /

Mootools: http://mootools.net/docs/core/Utilities/DomReady

Mootools: http://mootools.net/docs/core/Utilities/DomReady

Vanilla javascript:

Vanilla javascript:

window.onload = function() {
  // Code to be run.
} 

服务器之间不一致的原因可能是本地开发服务器加载页面比实时服务器更快。时间计算结果是你通常在两个地方都没有得到相同的错误 - 强调是因为如果你尝试了足够的时间,你可能会在两个地方重现错误。

The reason that this is inconsistent between servers could be that the local development server loads the page more quickly than the live server does. The timing works out so that you usually don't get the same error in both places - the emphasis is added because if you tried enough times, you would probably be able to reproduce the error in both places.

这篇关于" document.formName"未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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