javascript - In requireJS, why is the code in $(window).load() not executed?
黄舟
黄舟 2017-07-05 10:48:19
0
2
1189

I don’t know why, the code in $(window).load() will not be executed. I think it should be a problem with requireJS loading, but I don’t know exactly what happened, so I can’t use $(window).load. () function, please help everyone, thank you very much! ! !

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
世界只因有你

One benefit of using requireJS is that it can ensure that the js module is loaded in the order of dependencies you specify.
Back to your code, define is used to define a module and indicate that the module depends on XyEason. Therefore, requireJS will ensure that the callback function, which is function(XyEason), is executed after XyEason is loaded. The execution of the
callback function is asynchronous, and the load event occurs when the page is loaded. By the time this code is executed, the load event has already been triggered, so it will naturally not be executed.
Your code is equivalent to the following paragraph

setTimeout(function(){
  window.onload = function(){ alert("load") } //永远不会执行
},1000)
某草草

The key point is when you require(). If it is after the onload event, it will definitely not be triggered. I hope it can help you.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!