概括、在WEB中一共有四种方式可以引用js代码。
1、<script>直接引用代码</script>
2、<script src=xxx.js></script> //间接引用代码
3、<script defer>间接延迟引用代码</script>
4、javascipt:在地址栏中直接执行代码
示例:
<html> <head> <!--first run--> <script> alert("embedded script is in the head!"); </script> <!--second run--> <script src=out.js></script> <script defer>alert("delay script in the head!");</script> <!--在IE下是加载完body才运行,在firefox下是加载完head就运行--> </head> <body> <!--third run--> <script> alert("embedded script is in the body!"); </script> <!--fourth run--> <script src=out.js></script> <input type="button" value="button1" onclick='alert("button1 is clicked!")'/> <!--所有的事件都以on开头--> </body> </html> <!--还可以在地址栏中输入JavaScript代码,javascript:alert("script in the url!");-->
out.js
alert("out script!");
来源:https://www.cnblogs.com/eroshn/archive/2011/06/24/2088651.html