Run a javascript function on script load

て烟熏妆下的殇ゞ 提交于 2019-12-05 18:50:35

I think you’re looking for $.getScript. This jQuery function loads a JavaScript file from the server using a GET HTTP request and executes it. You can specify a callback function, to be executed after the script itself has been executed.

$.getScript('foo.js', function() {
 alert('foo.js was loaded, do something cool now');
});

I am curious about this myself, but instinct would tell me you'd want to wait for the document to finish loading before running any javascript.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!