[removed] Functions get called on page load instead of onclick/onsubmit

前端 未结 2 921
独厮守ぢ
独厮守ぢ 2021-01-05 16:14

I\'m relatively new to JS, but I have programmed in C before, and I\'m trying to get my head around the whole event driven nature of it. I\'m trying to create a script that

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-05 16:38

    yes your javascript function will call only when page will load .If you also want to call that init() function on click Test button so please try like this :

    JavaScript:

    function init(){ alert("hello"); }
    
    window.onload = init;
    HTML: 
    

提交回复
热议问题