错误提示:Uncaught TypeError: Cannot read property 'style' of undefined at HTMLDocument.myfun1请教各位!

错误提示:Uncaught TypeError: Cannot read property 'style' of undefined at HTMLDocument.myfun1请教各位!

元素跟随鼠标移动

错误提示:Uncaught TypeError: Cannot read property 'style' of undefined

这个错误是指 调用这个style属性的对象是 undefined
比如你的代码是 obj.style
就是指obj变量的值是 undefined,undefined不是对象,没法调用style属性
这种情况一般是因为用document.getElementById("id")没有获取到dom对象
或者也常见于数组下标越界的情况。
如你的代码是

for (var i = 0; i <= 6; i++)
    arr[i].style

比如arr数组下标只有0到5元素存放了有style属性的对象。
当i=6时下标越界, arr[i]的值就是 undefined

arr[i].style 也就成了 undefined.style

myfun1是函数还是标签呢?没有style属性。

有没有源代码呢,展示出来好解决。