在IE中的JavaScript对象所需的错误 [英] Javascript object required error in IE
本文介绍了在IE中的JavaScript对象所需的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在快乐的JavaScript创建多张地球对象来处理动画。
动画工作正常,每个行星,但我得到的错误在IE 6/7称上线所需的对象15字符2
code:
VAR earthObj = NULL;
VAR mercObj = NULL;
VAR jupiObj = NULL;
VAR动画;
功能的init()
{
mercObj =的document.getElementById('汞');
earthObj =的document.getElementById('土');
jupiObj =的document.getElementById('木星'); mercObj.style.position ='相对';
mercObj.style.left ='54px';
mercObj.style.visibility ='隐藏'; earthObj.style.position ='相对'; //错误在这条线
earthObj.style.left ='80px';
earthObj.style.top = 300像素';
}
解决方案
想如果存在调用对象,测试之前。
earthObj =的document.getElementById('土');
如果(!earthObj){
警报(无法找到地球);
返回;
}
i'm creating mulitple planet objects in javascript to handle animation.
The animation works fine for each planet but i am getting errors in IE 6/7 saying "object required on line 15 char 2"
Code:
var earthObj = null;
var mercObj = null;
var jupiObj = null;
var animate;
function init()
{
mercObj = document.getElementById('mercury');
earthObj = document.getElementById('earth');
jupiObj = document.getElementById('jupiter');
mercObj.style.position= 'relative';
mercObj.style.left = '54px';
mercObj.style.visibility = 'hidden';
earthObj.style.position= 'relative'; //error on this line
earthObj.style.left = '80px';
earthObj.style.top = 300px';
}
解决方案
Before trying to call an object, test if it exists.
earthObj = document.getElementById('earth');
if(!earthObj) {
alert("Could not find Earth");
return;
}
这篇关于在IE中的JavaScript对象所需的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文