Problem Description
很多人在写js代码的时候都遇到过这样的问题
Cannot set properties of null (setting 'innerHTML') , this error means that the attribute "innerHTML" of null cannot be read, indicating that the place where you want to insert the HTML code you want to write cannot be found.
Solution
At this time, we check the corresponding code of js according to the position of the error reminder
. After checking, we find that we have referenced a DOM node p here. We can add a p tag to it.
Add a p tag in the red box to ensure that the operation object is obtained.
summary:
- First of all, you should make sure whether you have obtained the operation object
- Second, consider reordering scripts or adding window.onload events