JavaScript嵌入页面的3种方式

JavaScript嵌入页面的3种方式

1、行间事件(主要用于事件)

2、页面script标签嵌入

3、外部引入

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<!--嵌入js方式3 外联-->
	<script type="text/javascript" src="js/hello.js"></script>
	<!--嵌入js方式2 内嵌-->
	<script type="text/javascript">
	alert("helloworld2");
	</script>
</head>
<body>
<!--嵌入js方式1 行间事件-->
	<input type="button" name="" value="点击" οnclick="alert('helloworld1')">
</body>
</html>

hello.js文件

alert("hello world3");

运行结果

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章