html中调用的js文件错误报告,求高手解答
代码//JavaScriptDocumentwindow.onload=function(){varoUl=document.getElementById("navt")...
代码
// JavaScript Document
window.onload = function() {
var oUl = document.getElementById("navt");
var aLi = oUl.getElementsByTagName("li");
var i = 0;
for (i = 0; i < aLi.length; i++) {
aLi[i].timer = null;
aLi[i].speed = 0;
aLi[i].onmouseover = function() {
startMove(this, 250);
};
aLi[i].onmouseout = function() {
startMove2(this, 100);
};
}
};
huo'h错误的报告第五行:TypeError:oUl is null
chrome错误报告也是第五行:Uncaught TypeError: Cannot call method 'getElementsByTagName' of null
求高手解答
function startMove(obj, iTarget) {
if (obj.timer) {
clearInterval(obj.timer);
}
obj.timer = setInterval(function() {
doMove(obj, iTarget);
}, 30)
};
function doMove(obj, iTarget) {
obj.speed += 3;
if (Math.abs(iTarget - obj.offsetWidth) < 1 && Math.abs(obj.speed) < 1) {
clearInterval(obj.timer);
obj.timer = null;
}
else {
if (obj.offsetWidth + obj.speed >= iTarget) {
obj.speed *= -0.7;
obj.style.width = iTarget + "px";
}
else {
obj.style.width = obj.offsetWidth + obj.speed + "px";
}
}
};
问题过长了,发不出来 展开
// JavaScript Document
window.onload = function() {
var oUl = document.getElementById("navt");
var aLi = oUl.getElementsByTagName("li");
var i = 0;
for (i = 0; i < aLi.length; i++) {
aLi[i].timer = null;
aLi[i].speed = 0;
aLi[i].onmouseover = function() {
startMove(this, 250);
};
aLi[i].onmouseout = function() {
startMove2(this, 100);
};
}
};
huo'h错误的报告第五行:TypeError:oUl is null
chrome错误报告也是第五行:Uncaught TypeError: Cannot call method 'getElementsByTagName' of null
求高手解答
function startMove(obj, iTarget) {
if (obj.timer) {
clearInterval(obj.timer);
}
obj.timer = setInterval(function() {
doMove(obj, iTarget);
}, 30)
};
function doMove(obj, iTarget) {
obj.speed += 3;
if (Math.abs(iTarget - obj.offsetWidth) < 1 && Math.abs(obj.speed) < 1) {
clearInterval(obj.timer);
obj.timer = null;
}
else {
if (obj.offsetWidth + obj.speed >= iTarget) {
obj.speed *= -0.7;
obj.style.width = iTarget + "px";
}
else {
obj.style.width = obj.offsetWidth + obj.speed + "px";
}
}
};
问题过长了,发不出来 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询