为什么oDiv变量在函数外定义会报错
我想在函数外定义var div = document.getElementById("div");让每个函数都可以调用,但是会报错
而timer定义在函数外就没问题
var div = document.getElementById("div");
window.onload = function () {
div.onmouseover = function () {
startMove(0,10);
}
div.onmouseout = function () {
startMove(-200,-10);
}
}
chrome报错Uncaught TypeError: Cannot set property 'onmouseover' of null
safari报错TypeError: null is not an object (evaluating 'div.onmouseover = function () {
startMove(0,10);
}')