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");

運行結果

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