Calling js function declared in html file from a .js file

烈酒焚心 提交于 2019-12-04 20:14:26

So long as you load the JavaScript file after the function is delcared in the HTML (or only invoke the function after it is declared), then the function you declare will be available within the same JavaScript context. The actual file location doesn't matter, only the in-memory namespaces.

The default behavior in a browser is to block while loading JavaScript using script tags, so you can safely write the JavaScript resources in the order that you want them executed without worrying about the fact that the external file needs to be loaded (and unless explicitly controlled otherwise they all get pooled together in a global namespace).

Yes, you can call this as it would be in your .js file. Functions in JS are shared between files, as variables are, too.

Provided you make sure your js file is included after the script tag, there should be no problems with invoking rotateMessage

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