ボタンをクリックしたらイベントを発生したいのですが、
クリックしても何も反応がない状態で、ブラウザの検証ツールのコンソールには、
edit:52 Uncaught TypeError: Cannot read properties of null (reading 'addEventListener') at
とエラーが表示されている状態です。
edit.balde.php
1~省略~ 2<script> 3const test = document.getElementById("test"); 4 test.addEventListener('click', function(e){ 5 console.log('リンクがクリックされました。'); 6 // デフォルトのイベントをキャンセル 7 e.preventDefault(); 8 }, false); 9</script> 10~省略~ 11<form action="{{ route('member.update') }}" 12~省略~ 13</from> 14~省略~ 15<div> 16 <button type="submit" class="submit" id="test" form="change-myinfo"> 17 </button> 18 </div> 19~省略~
記述等に問題ありますでしょうか?
<script>~</script>を</body>の直前に置くとどうですか?
回答3件
あなたの回答
tips
プレビュー