Difference between setTimeout with and without quotes and parentheses

前端 未结 6 1302
甜味超标
甜味超标 2020-11-22 07:06

I am learning JavaScript and I have learned recently about JavaScript timing events. When I learned about setTimeout at W3Schools, I noticed a strange figure wh

6条回答
  •  执念已碎
    2020-11-22 07:38

    i think the setTimeout function that you write is not being run. if you use jquery, you can make it run correctly by doing this :

        function alertMsg() {
          //your func
        }
    
        $(document).ready(function() {
           setTimeout(alertMsg,3000); 
           // the function you called by setTimeout must not be a string.
        });
    

提交回复
热议问题