JavaScript错误:微软JScript运行时错误:'的document.getElementById(...)'为空或不是对象 [英] javascript error: Microsoft JScript runtime error: 'document.getElementById(...)' is null or not an object

查看:282
本文介绍了JavaScript错误:微软JScript运行时错误:'的document.getElementById(...)'为空或不是对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用JavaScript函数来显示一个模式窗口,我得到这个错误:

I am getting this error when I call a javascript function to display a modal window:

微软JScript运行时错误:'的document.getElementById(...)'为空或不是对象

Microsoft JScript runtime error: 'document.getElementById(...)' is null or not an object

在code块是:

else if (action=="officeview") {
    document.getElementById("OfficeContent").src="ChangeView.aspx";
    ShowFeatureModal('AppView','OfficeContent')

的目的是这种情况,确实存在。

The object is this situation, does exist.

错误是在引起的。
还有什么可能会导致错误?

Error is caused at: document.getElementById line. What else could be causing the error?

更新:结果
Index.aspx的呼吁,位于sysUtilities.js文件中的JavaScript函数。源文件又是一个单独的页面(ChangeView.aspx)

Update:
Index.aspx is calling the javascript function which is located in sysUtilities.js file. The source file is yet a seperate page (ChangeView.aspx)

推荐答案

如果的document.getElementById 未找到该元素,它将返回。如果您然后尝试获得的src 属性,你会得到这个错误。

If document.getElementById doesn't find the element, it will return null. If you then try to get the src property from null, you'll get this error.

你要么需要确保有一个与它的ID等于 OfficeContent 元素或做类似如下:

You'll either need to ensure the there's an element with its ID equal to OfficeContent or do something like the following:

else if (action=="officeview") {
    var officeContent = document.getElementById("OfficeContent")
    if (officeContent) {
        officeContent.src="ChangeView.aspx";
        ShowFeatureModal('AppView','OfficeContent')
    }
}

编辑:如果您正在使用ASP.NET,这看来你是要记住,如果他们是一个容器控件内您的ID可能会得到名称错位。在这种情况下,你必须确保使用客户端ID ,而不是普通的老式 ID 。事情是这样的:

If you're using ASP.NET, which it appears that you are, remember that your IDs might be getting name-mangled if they are inside a container control. In that case, you have to make sure to use the ClientID, not the plain old ID. Something like this:

document.getElementById("<%= OfficeContent.ClientID %>")

这篇关于JavaScript错误:微软JScript运行时错误:'的document.getElementById(...)'为空或不是对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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