1. ホーム
  2. ジャバスクリプト

Uncaught TypeError: nullのプロパティ'onclick'を設定できない。

2022-02-25 14:53:53
<パス


vueの使用において、エラーUncaught TypeErrorが発生した場合。Cannot set property 'onclick' of null, the reason is because the vue project is a loading order, when the page has not been loaded when the js code has been executed, because it can't get and Just write the code in the onload function

window.onload = function(){
		 var btn = document.querySelector('#btn');
		 btn.onclick = function(){
		 		 console.log('666');
		 }
	 }