1. ホーム
  2. ハイパーリンク

null のプロパティ 'onclick' を設定できません。

2022-02-25 17:12:02
<パス
    If there is not much js code, I used to write it in the <head> tag of the html page
 Today I wrote a click event, and when I tested the click event the browser reported an error, prompting
 Cannot set property 'onclick' of null.
 Finally learned that it was because the js file was read first and did not get the onclick event.
 Solution.
 Move the js code behind the button that needs to be clicked
 Or let the browser load the button node first before executing the JS
 i.e. add window.onload=function(){
 }