html页面中如何调用/加载javascript

标签: javascripthtml加载js   时间:2016-09-06
HTML页面要使用js,必须将js载入到该页面,网页载入加载javascript的方法有很多种,本文章通过实例向大家介绍页面中如何调用/加载javascript,需要的朋友可以参考一下。

使用script加载js

<html>
<head>
<title>Title of Document</title>
<script>

// All Your Javascript Code goes In Here Between the opening and closing script tags.
</script>

</head>
<body>
The content of
your page here.

</body>
</html>

 

html head头部加载js

<html>
<head>

<script>
alert("Do you see the page heading?");
</script>
</head>
<body>
<h1>Page heading</h1>
</body>
</html>

 

html body加载js

<html>
<head>
</head>
<body>
<h1>Page heading</h1>
<script>
alert("Do you see the page heading?");
</script>
</body>
</html>

 

html载入外部js文件

<html>
<head>
<title>Title of Document</title>
<script src="path-to-file/fileName.js"></script>
</head>
<body>
The content of
your page goes here.
</body>
</html>

 

混合加载js

<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--

//  -->
</script>
</head>
<body>
<p onclick="units = prompt('How many do you want','Enter quantity');alert('Cost per unit is $9.99, therefore total cost for ' + units + ' is ' + units * 9.99);">Click here to specify quantity</p>
</body>
</html>

原文地址:http://www.manongjc.com/article/1460.html

分享到