HTML嵌入JavaScript腳本
在<head>標(biāo)簽中使用<script>腳本標(biāo)簽
<html>
<head>
<title>HTML頁(yè)面嵌入JS_01</title>
<script language="javascript">
window.alert("Say Hello");
alert("Hello World!");
</script>
</head>
<body>
</body>
</html>
在HTML頁(yè)面中引入外部JavaScript文件
新建1.js文件,在該文件中編寫(xiě)如下程序:
alert("hello world!");
<html>
<head>
<title>HTML頁(yè)面嵌入JS_02</title>
<script language="javascript" src="1.js"></script>
<!--錯(cuò)誤的寫(xiě)法:-->
<script language="javascript" src="1.js" />
</head>
<body>
</body>
</html>
JavaScript直接嵌入到HTML標(biāo)簽中
<html>
<head>
<title>HTML頁(yè)面嵌入JS_03</title>
</head>
<body>
<input type="button" value="SayHello" onclick="javascript:alert('Hello1');alert('Hello2');"/>
</body>
</html>