WEB调用JavaScript的方式

概括、在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" οnclick='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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值