document.getElementById()在IE9上返回null [英] document.getElementById() returns null on IE9

查看:91
本文介绍了document.getElementById()在IE9上返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个弹出窗口,并且在使用Internet Explorer 9时遇到了一些困难.这是给我带来麻烦的代码段:

I'm working on a popup and i'm having some hard time with Internet Explorer 9. This is the piece of code that gives me trouble:

var popUp= document.getElementById('projectInfo');
popUp.style.left=(tempX-310)+'px';
popUp.style.top=(tempY-110)+'px';

在IE9(以前的版本中未测试)中,弹出窗口为null.另外,我尝试在主体关闭标签之前添加.js文件,并将函数包装在"document.ready()"函数中,但这些都不起作用.尽管相同的代码可以在Opera,Chrome和Firefox中完美运行. 有人知道发生了什么吗?

In IE9 (haven't tested in prior versions), popup is null. In adition, i've tried including my .js file just before the body closing tag and wrapping my function in a "document.ready()" function but none of this worked. The same code though works perfectly in Opera, Chrome and Firefox. Does anyone know what's going on?

注意:该函数在我的html的正文的onLoad属性中调用.

Note: The function is called in the body's onLoad atribute of my html.

推荐答案

如果不使用功能,将无法正常工作

Without using function it can't work

 window.onload = function() {
   var popUp= document.getElementById('projectInfo');
   popUp.style.left=(tempX-310)+'px';
   popUp.style.top=(tempY-110)+'px';
 }

这篇关于document.getElementById()在IE9上返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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