使用script 元素可以告訴瀏覽器把一段文本看作腳本,而不是HTML。無論腳本是鏈接到HTML文檔上的外部文件,還是直接嵌入頁面中,腳本都放在<script>...</script>標記對中。不同的瀏覽器可以給<script>標記設置不同的特性,來管理腳本。type 特性告訴瀏覽器,標記中的代碼應看作JavaScript。
<script type="text/javascript" ...>...<script>
一定要包含腳本的尾標記。把JavaScript 程序代碼行放在src 特性指定的外部文件中:
<script type="text/javascript" src="example.js"><script>
或者放在兩個標記之間:
<script type="text/javascript">
one or more lines of JavaScript code here
</script>
假如忘了尾標記,腳本就不能正確運行,頁面中其他地方的HTML 也會顯得很奇怪。
示例代碼:
<html>
<head>
<LINK href="${_currConText}/theme/css/css.css" type=text/css rel=stylesheet>
<script type="text/javascript" src="${_currConText }/js/hello.js"></script>
<title>hello js</title>
</head>
<body >
hello js
</body>
<script>
$(document).ready(function(){
alert("hello js");
});function hello(pageNum){
alert("hello js");
}
</script>
</html>