While writing JavaScript beginners get a lot of Uncaught TypeError: Cannot set property ‘…’ of null error message so what is the problem with the code?
在编写JavaScript时,初学者会遇到很多Uncaught TypeError:无法设置null错误消息的属性“…”,那么代码又是什么问题呢?
在JavaScript初始化期间定义对象 (Define Object During JavaScript Initialization)
Here is number one reason the object you try to access is not defined. It may define later. It is not a joke because if you are using JavaScript framework some java objects can be defined later. So for example if you are using jQuery following document ready function can help.
这是未定义您尝试访问的对象的第一原因。 可能会在以后定义。 这不是开玩笑,因为如果您使用JavaScript框架,则可以在以后定义一些Java对象。 因此,例如,如果您使用的是jQuery,则以下文档准备功能可以提供帮助。
$(document).ready(function() {
//Javascript code
}
翻译自: https://www.poftut.com/javascript-uncaught-typeerror-cannot-set-property-of-null-error-solutions/