js(javaScript)基础知识一:嵌入到html文件中的方式

方式一:<标签名 οnclick=" javaScript diam" >不常用

<!DOCTYPE html>
<html>
<head>
	<title>JavaScript嵌入的第一种方式</title>
</head>
<body>
	<!--实现功能是,用户点击按钮时会弹出对话框
		js是一门事件驱动器编程语言
		鼠标实际:click 
		事件句柄:onclick
		js的执行原理:在浏览器打开是不会运行
		事件在发生的时候,js代码才会执行
		--->
   JavaScript的第一种嵌入方式:<P>
   	<!--
   		js弹窗的方式:window.alert("消息内容")
   		--->
   	<input type="button" value="欢迎" onclick="window.alert('hello js')"/>
 	<input type="button" value="欢迎" onclick="alert('hell javaScript');
 	alert('well com to study javaScript');
 	alert('go go !')
 	"/>
</body>
</html>

第二种方式;<script  type="javascript/text" >代码块</script>

<!DOCTYPE html>
<html>
<head>
	<title>javaScript使用的第二种方式</title>
	<style type="text/css">
		input{
			size: 20;
			border: 1px solid red;
		}
	</style>
</head>
<body>
	javaScript嵌入的第二种方式 脚本块!<P>
		<script type="text/javascript">
			//javaScript脚本块  在脚本块种的代码,在页面打开的时候就会执行
			//而且遵循自上而下的顺序
			//脚本块在页面中可以出现多次,而且位置随意
			window.alert('helllo word');
			window.alert('helllo js');
		</script>
 <input type="button"  value="欢迎" onclick="alert('我喜欢javaScript')">
</body>
</html>

 第三种方式:<script type="javascript/text" src="xx.js”></script>

第三中方式:
<!DOCTYPE html>
<html>
<head>
	<title>第三种方式</title>
</head>
<body>
 <p>javaScript嵌入的第三中方式</p>
 <script type="text/javascript" src="1.js"></script><P>
 第二种方式:<P>
 <script type="text/javascript">
 	window.alert('hello  window');
 </script><p>
 第一种:
 <input type="button" value="欢迎" onclick="window.alert('第三在方式')">
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值