使用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>