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

错误提示:Uncaught TypeError: Cannot read property 'style' of undefined at HTMLDocument.myfun1请教各位!
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- CSDN专家-天际的海浪 2021-08-30 22:53关注
错误提示: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]的值就是 undefinedarr[i].style 也就成了 undefined.style
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用